django.db.migrations.exceptions.InconsistentMigrationHistory [英] django.db.migrations.exceptions.InconsistentMigrationHistory

查看:114
本文介绍了django.db.migrations.exceptions.InconsistentMigrationHistory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Django项目上运行 python manage.py migration 时,出现以下错误:

When I run python manage.py migrate on my Django project, I get the following error:

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/hari/project/env/local/lib/python2.7/site-     packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/hari/project/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
executor.loader.check_consistent_history(connection)
File "/home/hari/project/env/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 298, in check_consistent_history
connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency account.0001_initial on database 'default'.

我的用户模型如下:

class User(AbstractUser):
    place = models.CharField(max_length=64, null=True, blank=True)
    address = models.CharField(max_length=128, null=True, blank=True)

如何解决此问题?

推荐答案

您数据库中的django_migrations表是导致不一致的原因,仅从本地路径删除所有迁移将不起作用。

Your django_migrations table in your database is the cause of inconsistency and deleting all the migrations just from local path won't work.

您必须从数据库中截断django_migrations表,然后尝试再次应用迁移。它应该可以工作,但是如果不能运行,请再次运行makemigrations然后再进行迁移。

You have to truncate the django_migrations table from your database and then try applying the migrations again. It should work but if it does not then run makemigrations again and then migrate.

注意:请不要忘记备份数据。

Note: don't forget to take a backup of your data.

这篇关于django.db.migrations.exceptions.InconsistentMigrationHistory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆