gpt4 book ai didi

django - django 1.8无法执行django.db.utils.ProgrammingError:关系“auth_user”不存在

转载 作者:行者123 更新时间:2023-12-03 13:26:21 27 4
gpt4 key购买 nike

我有一个使用django 1.7的工作项目,现在我将其移至django 1.8。
我可以执行syncdb并使用sqlite运行应用程序,但是当我切换到postgres时,它无法执行syncdb:

  Creating tables...
Creating table x
Creating table y
Running deferred SQL...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "~/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "~/venv/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 "~/venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "~/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "~/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "~/venv/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "~/venv/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


我尝试删除数据库并重新创建它。
另外,我尝试了:

python manage.py migrate auth


这也失败了:

django.db.utils.ProgrammingError: relation "django_site" does not exist

LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1


请帮助解决此问题。

最佳答案

我不喜欢注释/取消注释代码的想法,因此尝试了另一种方法:我“手动”迁移了一些应用程序,然后为其余的应用程序运行django-admin.py migrate。删除所有*.pyc文件后,我的命令顺序为:

$ django-admin.py migrate auth
$ django-admin.py migrate contentypes
$ django-admin.py migrate sites
$ django-admin.py migrate MY_CUSTOM_USER_APP
$ django-admin.py migrate


其中, MY_CUSTOM_USER_APP是包含我在 AUTH_USER_MODEL文件中设置了 settings的模型的应用程序的名称。

希望能有所帮助。顺便说一句,在Django 1.8中同步数据库的最佳方法如此复杂似乎很奇怪。我想知道我是否缺少某些东西(我对Django 1.8不太熟悉,我曾经使用过较旧的版本)

关于django - django 1.8无法执行django.db.utils.ProgrammingError:关系“auth_user”不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30897442/

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