django 1.8 failed to django.db.utils.ProgrammingError:relation“auth_user”不存在 [英] django 1.8 fails to django.db.utils.ProgrammingError: relation "auth_user" does not exist

查看:1209
本文介绍了django 1.8 failed to django.db.utils.ProgrammingError:relation“auth_user”不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 创建表... 
创建表x
创建表y
运行延迟SQL ..
追溯(最近的最后一次调用):
文件manage.py,第10行,< module>
execute_from_command_line(sys.argv)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / __ init__.py,第338行,execute_from_command_line
utility.execute()
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / __ init__.py,第330行,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / base.py,第390行,在run_from_argv
自身。执行(* args,** cmd_options)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / base.py,第441行,执行
输出= self.handle(* args,** options)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / commands / syncdb.py
call_command(migrate,** options)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / __ init__.py,第120行,call_command
return command.execute(* args,** defaults)
文件〜 /venv/lib/python2.7/site-packages/django/core/management/base.py,第441行,执行
output = self.handle(* args,** options)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / commands / migrate.py,第179行,处理
created_models = self.sync_apps(connection,executor.loader。 unmigrated_apps)
文件〜/ venv / lib / python2.7 / site-packages / django / core / management / commands / migrate.py,第317行,sync_apps
cursor.execute(statement)
文件〜/ venv / lib / python2.7 / site-packages / django / db / backends / utils.py,第79行,执行
return super(CursorDebugWrapper,self).execute sql,params)
文件〜/ venv / lib / python2.7 / site-packages / django / db / backends / utils.py,第64行,执行
return self.cursor.execute (sql,params)
文件〜/ venv / lib / python2.7 / site-packages / django / db / utils.py,第97行,__exit__
six.reraise(dj_exc_type,dj_exc_value ,traceback)
文件〜/ venv / lib / python2.7 / site-packages / dja ngo / db / backends / utils.py,第62行,执行
return self.cursor.execute(sql)
django.db.utils.ProgrammingError:relationauth_user不存在

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

  python manage.py migrate auth 

哪些也失败:

  django.db。 utils.ProgrammingError:关系django_site不存在

LINE 1:SELECT(1)ASaFROMdjango_siteLIMIT 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 的模型的应用程序的名称。



希望可以帮助。 Btw,似乎很奇怪,在Django 1.8中同步数据库的最佳方式是如此复杂。我想知道我是否缺少某些东西(我不太熟悉Django 1.8,以前用旧版本)


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

which also fails:

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

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

Please help get this fixed.

解决方案

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

where MY_CUSTOM_USER_APP is the name of the application containing the model I set AUTH_USER_MODEL to in my settings file.

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 failed to django.db.utils.ProgrammingError:relation“auth_user”不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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