gpt4 book ai didi

django - 为什么在安装了 "auth_user does not exist"应用程序的新创建的 django 项目上运行 "migrate"时会出现 "registration redux"错误?

转载 作者:行者123 更新时间:2023-12-04 10:07:10 25 4
gpt4 key购买 nike

给定一个新创建的 django 项目,其中安装了以下应用程序:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
)

当我第一次运行 ./manage.py migrate 时,我收到以下错误:
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages, registration
Apply all migrations: sessions, admin, auth, contenttypes
Synchronizing apps without migrations:
Creating tables...
Creating table registration_registrationprofile
Running deferred SQL...
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/tcosta/Virtualenvs/django_project/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist```

似乎 Django 正在尝试在用户表之前创建注册表。

如果我注释注册应用程序并运行迁移,然后取消注释注册应用程序并再次运行迁移,则不会发生此错误。然而,这不是正确的做法,对吧?

最佳答案

更新我的 Django 版本后,我收到此错误并修复为运行这两行:

python manage.py migrate auth
python manage.py migrate

auth 模型中的 auth_user 表应该首先运行我猜。

关于django - 为什么在安装了 "auth_user does not exist"应用程序的新创建的 django 项目上运行 "migrate"时会出现 "registration redux"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994606/

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