python - Django Makemigrations 和 Migrate 不断重复

标签 python django django-models

我的 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

当我迁移

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

我尝试过伪造迁移来解决这个问题,但没有成功。这是一个问题,因为任何新的更改都没有注册到我的模型中。

编辑:

显示迁移:

对于我的OM

[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

最佳答案

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

Synchronizing apps without migrations:

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

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

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

附注如果你不知道什么是假迁移,check out the explanation .

关于python - Django Makemigrations 和 Migrate 不断重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59851113/

相关文章:

django - 如何按 django 中的自定义区域过滤位置?

django - 如何计算 Django 模型中某些字段的平均值并将其发送到 rest API?

python - 从多个模型创建模型以添加到数据库?

python - 使用 return 的优缺点(yield from some_function())

python - 属性错误 : 'module' object has no attribute 'open'

python - 在 python 中过滤包含一组字符串的数据帧行

python - 如何在django中过滤没有被关注的用户

python - 如何使用 django 配置 apache?

python - Django - 在查询中加入 2 个模型

python - python程序中不需要的换行符