我正在Django中更改一个应用程序名称,并遇到这个InconsistentMigrationHistory
异常
我做的第一件事,如this SO answer中所述,是更改应用程序目录的名称和对应用程序的所有引用
我在django_content_type
表和django_migrations
表中使用了一些SQL语句将account
重命名为authentication
。我还重命名了此应用程序型号的表
完成这些操作后,运行python manage.py makemigrations
或python manage.py migrate
我会得到如下所示的InconsistentMigrationHistory
异常
回溯:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/Users/ramonaspence/.local/share/virtualenvs/chefs-notebook-2vB4UyAE/lib/python3.7/site-packages/django/db/migrations/loader.py", line 306, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration account.0001_initial is applied before its dependency authentication.0001_initial on database 'default'.
这里,account
是旧的应用程序名,authentication
是新的应用程序名
除了这个例外,我的第一个想法是在account
中必须有一个迁移文件,它使用authentication.0001_initial
迁移作为依赖项。然而,这种迁移并不存在,在我的数据库中也不存在
出于这个原因,我排除了these solutions
我已经从django_migrations表中删除了account
迁移,但是运行showmigrations
命令将应用app account
的迁移
当我运行命令时
python manage.py migrate -fake account zero
或
python manage.py migrate account zero
我也犯了同样的错误
我是否需要完全删除此应用的迁移记录?或者是否有其他方法取消应用这些迁移
编辑:我的问题似乎是在取消应用迁移文件之前删除了它们
目前没有回答
相关问题 更多 >
编程相关推荐