python - django.db.migrations.exceptions.InconsistentMigrationHistory : Migration . ..在其依赖项之前应用

标签 python django database-migration

我得到这个异常:

myproject@aptguettler:~$ manage.py migrate
Traceback (most recent call last):
  File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 32, in <module>
    main()
  File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 29, in main
    execute_from_command_line()
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor.loader.check_consistent_history(connection)
  File "/home/myproject/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 292, in check_consistent_history
    connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration myapp.0029_bar is applied before its dependency myapp.0005_foo_squashed_0028_dynamic_year on database 'default'.

我的迁移:

                   name                    
-------------------------------------------
 0001_initial
 0002_...
 0003_...
 0004_...
 0005_foo
 0006_...
 0007_...
...
 0028_dynamic_year
 0029_bar
 0030_...

可能是什么原因?

最佳答案

在队友的帮助下我找到了原因。

他这样做了:

  1. 压制迁移
  2. 生产部署和 makemigrations
  3. 删除了迁移目录中压缩的 python 文件

我更新了我的(旧)开发系统中的 git 存储库。然后进行迁移引发上述异常。

Django 无法解决这个问题,因为有些迁移已应用,有些则未应用,而且旧的压缩迁移文件不再可用。

我采用了最简单的解决方案:我删除了开发数据库并从头开始创建它。

关于python - django.db.migrations.exceptions.InconsistentMigrationHistory : Migration . ..在其依赖项之前应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49154158/

相关文章:

python - 滚动最大值不包括 Pandas 1.0 中的当前观察值

python - 使用 Google Docs List API、Python 和 OAuth 2 进行身份验证

python - 如何使用 Django 重命名模型?

oracle - DDL Oracle 到 Postgres 的转换

python - Apache Thrift Python 3 支持

python - 按日期对元组列表进行排序

python - 在 Django Rest Framework 中使用 Tokenauthentication 进行身份验证时,last_login 字段未更新

python - 如何从 Django 管理上传多个文件?

django - Django 批量创建检查已经存在于批量对象和实例中?

c# - ASP MVC MsSql 到 MySQL 迁移