为什么在运行“ migrate”时出现“ auth_user不存在”错误?在新创建的带有“ registration redux”的django项目上应用安装了吗? [英] Why do I get a "auth_user does not exist"error when running "migrate" on a newly created django project with "registration redux" app installed?

查看:223
本文介绍了为什么在运行“ migrate”时出现“ auth_user不存在”错误?在新创建的带有“ registration redux”的django项目上应用安装了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下已安装的应用程序创建一个新的django项目:

Given a newly created django project with the following installed apps:

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

当我第一次运行./manage.py时,出现以下错误:

When I run ./manage.py migrate for the first time I get the following error:

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试图在创建注册表之前用户表。

It seems Django is trying to create the registration tables before the user table.

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

This erros does not happen if I comment the registration app and run migrate and then uncomment the registration app and run migrate again. However, that's not the right way of doing it, right?

推荐答案

更新Django版本后,出现此错误并修复运行以下两行:

After updating my Django version, I got this error and fix as running these two lines:

python manage.py migrate auth
python manage.py migrate

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

auth_user table inside auth model should run first I guess.

这篇关于为什么在运行“ migrate”时出现“ auth_user不存在”错误?在新创建的带有“ registration redux”的django项目上应用安装了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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