解决Django migrate No changes detected 不能创建表的问题
作者:hanglinux 时间:2021-03-08 12:21:34
起因
修改了表结构以后执行python3 manage.py migrate 报错:
django.db.utils.OperationalError: (1091, "Can't DROP 'email'; check that column/key exists")
所以进数据库把对应的表删除了,想着重新生成这张表.
删除表以后执行:
python3 manage.py makemigrations
python3 manage.py migrate
还是不能生成表,提示:No changes detected
处理过程
首先删除了app对应目录下的数据库对应的文件和缓存文件:
$ rm -rf migrations/ __pycache__/
重新执行:
$ python3 manage.py makemigrations
No changes detected
$~/code/django/blogproject$ python3 manage.py makemigrations comments
Migrations for 'comments':
comments/migrations/0001_initial.py
- Create model Comment
$~/code/django/blogproject$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, blog, comments, contenttypes, sessions, users
Running migrations:
No migrations to apply.
进入数据库发现仍然没有生成表.
然后发现有一张django_migrations表,里面记录这有关创建表的记录,删除对应的数据表:
delete from django_migrations where app='yourappname';
重新执行生成数据库命令:
$ python3 manage.py makemigrations comments
No changes detected in app 'comments'
$~/code/django/blogproject$ python3 manage.py migrate comments
Operations to perform:
Apply all migrations: comments
Running migrations:
Applying comments.0001_initial... OK
数据表顺利生成.
结论
在执行
python3 manage.py makemigrations python3 manage.py migrate
操作的时候,不仅会创建0001_initial.py对应的模型脚本,还会创建一个数据库记录创建的模型.如果想重新生成数据库,需要两个地方都做删除.
来源:https://blog.csdn.net/hanglinux/article/details/75645756
标签:changes,detected,Django,migrate
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP如何输出字符
2007-09-22 18:41:00
网页打开速度的心理学
2009-03-26 13:18:00
解构用户研究
2010-03-15 12:34:00
![](https://img.aspxhome.com/file/UploadPic/20103/15/deconstructing_user_research_banner730-250-33s.jpg)
常见Dreamweaver使用过程中的问题及解决办法
2011-03-17 16:16:00
提高javascript的速度系列(序)
2008-07-15 12:38:00
Js中的函数直接量
2007-12-21 19:15:00
Python OpenCV简单的绘图函数使用教程
2023-08-02 23:22:22
![](https://img.aspxhome.com/file/2023/7/61197_0s.jpg)
golang 使用sort.slice包实现对象list排序
2023-06-21 18:25:46
![](https://img.aspxhome.com/file/2023/2/87612_0s.png)
python脚本框架webpy入门安装及应用创建
2023-08-23 05:08:51
详解Python:面向对象编程
2023-10-26 16:17:53
JavaScript实现三种常用网页特效(offset、client、scroll系列)
2023-08-27 11:54:30
![](https://img.aspxhome.com/file/2023/3/56173_0s.png)
编写SQL Server的扩展存储过程实例
2009-01-20 15:45:00
MySQL字符集查看方法
2010-12-14 15:14:00
自定义数据库自动编号初始值和步进值
2009-05-19 10:00:00
向外扩展SQL Server 实现更高扩展性
2008-12-18 14:45:00
Python使用captcha制作验证码的实现示例
2023-04-16 00:49:35
![](https://img.aspxhome.com/file/2023/3/75113_0s.png)
微信小程序页面缩放式侧滑效果的实现代码
2023-09-02 05:21:45
![](https://img.aspxhome.com/file/2023/4/56264_0s.gif)
Dreamweaver虚拟在线试衣室
2009-07-05 18:54:00
![](/images/sg_trans.gif)
web标准页面知识必备 Ⅰ
2008-03-06 13:24:00
eWebEditor不支持IE8/IE7的解决方法
2010-02-28 10:27:00
![](https://img.aspxhome.com/file/UploadPic/20102/28/4270100787_166776e513_o-72s.jpg)