简体   繁体   English

django.db.utils.ProgrammingError:关系“auth_user”不存在

[英]django.db.utils.ProgrammingError: relation “auth_user” does not exist

When trying to do a syncdb in Django it fails with the follow traceback. 当尝试在Django中执行syncdb时,它会失败,并带有跟踪回溯。 I've tried deleting the schema and creating a clean one. 我已经尝试删除模式并创建一个干净的模式。 migrate creates the migration but it never creates any of the tables outside of django_migrations . migrate会创建迁移,但它永远不会创建django_migrations之外的任何表。 I've also deleted all existing pyc files as a precaution but no luck. 我还删除了所有现有的pyc文件作为预防措施,但没有运气。 It doesn't seem to be creating any of the tables on initial sync. 它似乎没有在初始同步时创建任何表。 Currently not dealing with any models outside of the core tables created (auth, sessions, etc.) 目前没有处理创建的核心表之外的任何模型(auth,sessions等)

System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
System check identified some issues:

WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
Operations to perform:
  Synchronize unmigrated apps: oauth2_provider, core, django_admin_bootstrapped, rest_framework_swagger, rest_framework, django_admin_bootstrapped_bootstrap3
  Apply all migrations: admin, contenttypes, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying sessions.0001_initial... OK
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 36, in handle_noargs
    if not UserModel._default_manager.exists() and options.get('interactive'):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 606, in exists
    return self.query.has_results(using=self.db)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 445, in has_results
    return compiler.has_results()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 757, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
LINE 1: SELECT (1) AS "a" FROM "auth_user" LIMIT 1

I was having this problem in Django 1.8, where I'm using a custom user profile which I, as recommended in the documentation, created with a OneToOneField to the user. 我在Django 1.8中遇到了这个问题,我正在使用自定义用户配置文件,我在文档中建议使用OneToOneField创建用户。

Luckily, I isolated the user profile code in a separate app which I called "profile". 幸运的是,我在一个单独的应用程序中隔离了用户配置文件代码,我称之为“配置文件”。

For me, this workaround solved the problem: 对我来说,这个解决方法解决了这个问题:

  • Disable the custom user profile by disabling the "profile" app in settings.py by removing it from INSTALLED_APPS 通过从settings.py中删除“profile”应用程序来禁用自定义用户配置文件,方法是将其从INSTALLED_APPS中删除
  • Run python manage.py migrate 运行python manage.py migrate
  • Re-enable the custom user profile by re-inserting the app. 通过重新插入应用程序重新启用自定义用户配置文件。

This is most certainly due to a bug in Django. 这肯定是由于Django中的一个错误。

I had very similar issue. 我有类似的问题。 Eventually I've discovered that not all of my apps had migrations. 最后我发现并非所有应用都有迁移。 So check if all of your installed apps (Django project wise) which have models.py files have migrations as well. 因此,请检查具有models.py文件的所有已安装应用程序(Django项目明智)是否也具有迁移功能。 That solved my issue (forcing Django to create migrations for specific app) and also checking that migrations.swappable_dependency(settings.AUTH_USER_MODEL), is listed and on the first position in migration dependencies. 这解决了我的问题(强制Django为特定应用程序创建迁移),还检查了migrations.swappable_dependency(settings.AUTH_USER_MODEL),并列出了迁移依赖项中的第一个位置。

This error occurs with the multiple databases I had setup with my previous version of django (1.5). 我使用之前版本的django(1.5)设置的多个数据库发生此错误。 The upgrade did not take to the multiple databases with south. 升级没有带到南方的多个数据库。 Eventually I will have to re-visit this so that I can attempt migrations but in the meantime I have scrapped this. 最终我将不得不重新访问这个以便我可以尝试迁移,但与此同时我已经废弃了这个。 Removing the multiple database instances in my settings.py resolved the issue. 删除settings.py中的多个数据库实例解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django.db.utils.ProgrammingError:关系“ auth_user”不存在-django 2.0.2 - django.db.utils.ProgrammingError: relation “auth_user” does not exist - django 2.0.2 django.db.utils.ProgrammingError:关系“...”不存在 - django.db.utils.ProgrammingError: relation “…” does not exist django.db.utils.ProgrammingError:关系“-”不存在 - django.db.utils.ProgrammingError: relation “ - ” does not exist 在 manage.py 测试期间“django.db.utils.ProgrammingError:关系“app_user”不存在” - "django.db.utils.ProgrammingError: relation "app_user" does not exist" during manage.py test Django 迁移数据库 django.db.utils.ProgrammingError:关系“django_site”不存在 - Django Migrating DB django.db.utils.ProgrammingError: relation "django_site" does not exist Django 测试失败,出现“django.db.utils.ProgrammingError:关系“django_content_type”不存在” - Django test fails with 'django.db.utils.ProgrammingError: relation "django_content_type" does not exist' Django Rest框架“ django.db.utils.ProgrammingError:关系“患者”不存在” - Django Rest Framework “django.db.utils.ProgrammingError: relation ”patient“ does not exist” django.db.utils.ProgrammingError:关系“ogs_features_product”的“价格”列不存在 - django.db.utils.ProgrammingError: column "Price" of relation "ogs_features_product" does not exist django.db.utils.ProgrammingError:关系“APP_profile”的“角色”列不存在 - django.db.utils.ProgrammingError: column "role" of relation "APP_profile" does not exist django.db.utils.ProgrammingError:关系“blog_category”不存在 - django.db.utils.ProgrammingError: relation "blog_category" does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM