django 1.8 无法 django.db.utils.ProgrammingError: 关系“auth_user"不存在 [英] django 1.8 fails to django.db.utils.ProgrammingError: relation "auth_user" does not exist
问题描述
我有一个使用 django 1.7 的工作项目,现在我将其移至 django 1.8.我可以执行 syncdb
并使用 sqlite 运行应用程序,但是当我切换到 postgres 时,它无法执行 syncdb:
I had a working project with django 1.7, and now I moved it to django 1.8.
I can do syncdb
and run the app with sqlite, but when I switch to postgres, it fails to do 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
我尝试删除数据库并重新创建它.另外,我试过:
I tried deleting the database and recreating it. Also, I tried:
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
文件后,我的命令序列是:
I didn't like the idea of commenting/uncommenting code, so I tried a different approach: I migrated "manually" some apps, and then run django-admin.py migrate
for the remaining ones. After deleting all the *.pyc
files, my sequence of commands was:
$ 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
是包含我在 settings
文件中设置的 AUTH_USER_MODEL
模型的应用程序的名称.
where MY_CUSTOM_USER_APP
is the name of the application containing the model I set AUTH_USER_MODEL
to in my settings
file.
希望能帮到你.顺便说一句,在 Django 1.8 中同步数据库的最佳方法是如此复杂,这似乎很奇怪.我想知道我是否遗漏了什么(我对 Django 1.8 不是很熟悉,我曾经使用过旧版本)
Hope it can help. Btw, it seems strange that the best way to synchronize your db in Django 1.8 is so complicated. I wonder if I'm missing something (I'm not very familiar with Django 1.8, I used to work with older versions)
这篇关于django 1.8 无法 django.db.utils.ProgrammingError: 关系“auth_user"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!