首页 > 解决方案 > Django Makemigrations 和 Migrate 不断重复

问题描述

我的 django 应用程序似乎发生了一些事情。有两种模型,一种是我修改的,另一种是新添加的。自从这两个变化以来,我的变化随着迁移数量的增加makemigrationsmigrate继续保持不变。当我makemigrations

Migrations for 'om':
  0033_auto_20200122_0001.py:
    - Alter field delivery_date on growerpurchaseorderitem
Migrations for 'accounts':
  0105_auto_20200122_0001.py:
    - Alter field created on pushtoken
    - Alter field push_token on pushtoken

当我migrate

Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying accounts.0105_auto_20200122_0001... OK
  Applying om.0033_auto_20200122_0001... OK

我试图伪造迁移以克服这个问题,但没有运气。这是一个问题,因为任何新的更改都没有注册到我的模型中。

编辑:

显示迁移:

为了我的妈妈

[X] 0030_auto_20200121_2339
 [X] 0031_auto_20200121_2343
 [X] 0032_auto_20200121_2348
 [X] 0033_auto_20200122_0001

我的帐户

[X] 0099_certpdf_expiration_date
 [X] 0100_pushtoken
 [X] 0101_auto_20200121_2145
 [X] 0102_auto_20200121_2339
 [X] 0103_auto_20200121_2343
 [X] 0104_auto_20200121_2348
 [X] 0105_auto_20200122_0001

标签: pythondjangodjango-models

解决方案


根据我的研究,这很可能是程序出错的地方:

Synchronizing apps without migrations:

尝试创建迁移,然后伪造第一个迁移:

python manage.py makemigrations <app_name>
python manage.py migrate --fake-initial

这些命令将跳过已创建表的任何迁移。

PS 如果您不知道什么是虚假迁移,请查看说明


推荐阅读