gpt4 book ai didi

python - django.db.migrations.exceptions.InconsistentMigrationHistory

转载 作者:IT老高 更新时间:2023-10-28 21:48:11 30 4
gpt4 key购买 nike

当我在我的 Django 项目上运行 python manage.py migrate 时,我收到以下错误:

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)

我该如何解决这个问题?

最佳答案

由于您使用的是自定义用户模型,因此您可以执行 4 个步骤:

  1. 在 INSTALLED_APPS 设置中注释掉 django.contrib.admin
INSTALLED_APPS = [
...
#'django.contrib.admin',
...
]
  1. 在 urls.py 中注释掉管理路径
urlpatterns = [
...
#path('admin/', admin.site.urls)
...
]
  1. 然后运行
 python manage.py migrate
  1. 完成后,全部取消注释

关于python - django.db.migrations.exceptions.InconsistentMigrationHistory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44651760/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com