django Version: 2.2.3
更新了models.py
后,执行
root@:collection:/code# python manage.py makemigrations No changes detected root@:collection:/code# python manage.py migrate Operations to perform: Apply all migrations: account, admin, auth, authtoken, sessions, sites, socialaccount, template Running migrations: No migrations to apply.
看上去是检测不到models.py
有变化一样,有什么解决办法吗,很头疼的问题
![]() | 1 xujunfu 2019-10-29 15:48:59 +08:00 |
3 css3 OP @xujunfu root@collection:/code# python manage.py makemigrations project Migrations for 'project': apps/project/migrations/0001_initial.py - Create test Module - Add field env to test - Alter unique_together for module (1 constraint(s)) root@collection:/code# python manage.py migrate project Operations to perform: Apply all migrations: project Running migrations: No migrations to apply. |
4 Jammar 2019-10-29 16:07:22 +08:00 删掉 migrations 重新迁移 |
![]() | 5 Hopetree 2019-10-29 16:09:26 +08:00 把迁移的文件都删掉,之保留__init__.py ,然后重新生成 |
![]() | 7 libaibuaidufu 2019-10-29 16:15:25 +08:00 没有在 settings 中 添加对应模块? |
![]() | 8 careofzm 2019-10-29 16:15:57 +08:00 去数据库里的 django_migrate 表看一下, 看是不是已经生成了, 这个表是记录执行迁移操作的 |
![]() | 9 est 2019-10-29 16:19:44 +08:00 多 db 需要单独制定迁移哪一个 db。 |
10 hmxxmh 2019-10-29 16:20:05 +08:00 是否是你修改了某个表,新增了字段,但是没给默认值,这样迁移会失败。 |
![]() | 11 ksedz 2019-10-29 16:29:01 +08:00 managed 是 False ?或者自定义 database router 里面逻辑不对? |
![]() | 12 lzj307077687 2019-10-29 16:29:57 +08:00 django_migrations 表清掉? |
![]() | 13 css3 OP @libaibuaidufu 加了 |
![]() | 15 libaibuaidufu 2019-10-29 17:48:05 +08:00 我感觉有时候会莫名的无法检测到 model 变化,一般都是重来。。。 没仔细深究过。。。 |
![]() | 16 css3 OP @libaibuaidufu +10000不知道原因,只能删库重来 |
17 laoyur 2019-10-29 17:51:32 +08:00 managed 一开始是 False,后来又改回 True 了吧?再改回 True 后,它会跳过你那个 Model 类的 |
18 shanguo 2019-10-29 18:10:20 +08:00 在 models 包里面的 __init__.py 里面导入 你的 TestModel 举例: models/ __init__.py user.py 在 __init__.py 里面 导入你的 UserModel 然后在执行 makemigrations,migrate |
![]() | 19 wuwukai007 2019-10-30 18:57:54 +08:00 你是不是用了自定义用户类,AbstractUser,然后又改了,如果这样要到 django 源码里面删 makemigrations 文件,有缓存的 |
![]() | 21 css3 OP @wuwukai007 没这样操作啊 |