解决Django报错:No changes detected

No changes detected迁移Django
2023-09-20 16:22:15

Django不能创建表的问题 No changes detected

现象是,我的项目下面migrations目录被删除,导致迁移记录被删掉,那么挽救的机会渺茫,其实还是可以挽救的。

Django:No changes detected
Django:No changes detected

以我的报错为例

找到数据表(本人部署的默认sqilte,mysql类似)

  • 找到迁移记录表,django_migrations

select * from django_migrations;

id | app | name | applied
-|-|-
1 | contenttypes | 0001_initial | 2019-02-22 20:27:44.547476
2 | auth | 0001_initial | 2019-02-22 20:27:44.630780
3 | admin | 0001_initial | 2019-02-22 20:27:44.683807
4 | admin | 0002_logentr |2019-02-22 20:27:44.739872
5 | contenttypes | 0002_remove_ | 2019-02-22 20:27:44.828763
6 | auth | 0002_alter_p |2019-02-22 20:27:44.881538
7 | auth | 0003_alter_u |2019-02-22 20:27:44.931404
14 | sessions | 0001_initial | 2019-02-22 20:27:45.254584
58 | contenttypes | 0001_initial |2019-02-22 19:19:47.317079
59 | article_mana | 0001_initial |2019-02-22 21:05:40.716135
60 | article_mana |0002_auto_20 |2019-02-24 14:43:28.783517

  • 找到需要增加的APP名称,并删除表记录(我的是article_mana)

delete from django_migrations where app='article_mana'

删除之后切记先注释原先增加的字段

执行 python manage.py makemigrations article_mana ,会看到生成新的迁移记录

Django :python manage.py makemigrations
Django :python manage.py makemigrations

再执行python manage.py migrate article_mana

  • 取消原来的字段的注释,正常流程再迁移

作者微信:bianbingdang。转载请注明,变饼档博客