Django 'migration is applied before its dependency' when 运行 任何迁移命令

Django 'migration is applied before its dependency' when running any migration commands

我正在使用连接到本地 MySQL database.My 项目的 Django 3.0.2 当前有 2 个应用程序,“accounts”和“'.

我在更新一些模型字段后删除了数据库中的所有表,并删除了迁移文件夹中除 __init__.py 之外的所有文件。尝试启动开发服务器显示错误:Dependency on app with no migrations: accounts,所以我 运行 python manage.py makemigrations 返回了这个

Migrations for 'accounts':
  accounts\migrations[=12=]01_initial.py
    - Create model User
Migrations for 'home':
  home\migrations[=12=]01_initial.py
    - Create model Idea
    - Create model Reply

在此之后,运行 服务器发出警告说

You have 1 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): accounts. Run 'python manage.py migrate' to apply them.

这样做会给我一个 InconsistentMigrationHistory 异常: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'


运行 python manage.py showmigrations returns 这个:

accounts
 [ ] 0001_initial
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
home
 [X] 0001_initial
sessions
 [X] 0001_initial

我试过以不同的顺序运行这些命令,但最终得到了相同的结果。如果需要,我可以提供有关该应用程序的更多详细信息。

我希望你还没有清除你的模型class。您可以删除应用程序目录的迁移目录下的所有文件,不包括 init.py 文件。 你必须放弃 table django_migrations。 删除后 运行

python manage.py makemigrations account
python manage.py makemigrations home
python manage.py migrate