django-custom-user和custom_user_emailuser(不存在)

时间:2015-05-25 19:44:13

标签: python django django-south django-custom-user

TL; DR - 使用django-custom-user django-registration-redux,即使在原始实例上也无法设置postgres数据库。它抱怨不存在关系,我不明白为什么或在哪里。下面问题的详细信息不长,但包含一些中等长度的错误摘要。任何指针都非常赞赏。

使用django-custom-user,我了解到在剩余的迁移工作之前我必须先为custom_user进行迁移。很公平。在一个干净的实例上(刚刚创建了一个数据库并git克隆了代码),我输入

python manage.py makemigrations custom_user
python manage.py makemigrations
python manage.py migrate

但是......不,我缺少custom_user_emailuser。我怀疑这意味着来自关键emailuser上的custom_user的关系,但我仍然发现自己难以理解它的来源,以及如何处理它。任何提示都非常感激。

╭╴ (user-model-74=) [virt]╶╮
╰ [T] django@beta11:django $ python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: admindocs, kernel, messages, staticfiles, blog
  Apply all migrations: custom_user, sites, auth, sessions, contenttypes, registration, admin
Synchronizing apps without migrations:
  Creating tables...
Creating table blog_blogentry
Creating table kernel_userprofile
Creating table kernel_trippending
Running deferred SQL...
Traceback (most recent call last):
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "custom_user_emailuser" does not exist


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/src/django/venv/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "custom_user_emailuser" does not exist

╭╴ (user-model-74=) [virt]╶╮
╰ 1,[T] django@beta11:django $

我不明白,更糟糕的是因为custom_user迁移不会调用这样的东西:

╭╴ (user-model-74=) [virt]╶╮
╰ [T] django@beta11:django $ more venv/lib/python3.4/site-packages/custom_user/migrations/0001_initial.py 
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
    ('auth', '0006_require_contenttypes_0002'),
]

operations = [
    migrations.CreateModel(
    name='EmailUser',
    fields=[
        ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_nam
e='ID')),
        ('password', models.CharField(verbose_name='password', max_length=128)),
        ('last_login', models.DateTimeField(null=True, blank=True, verbose_name='last login')),
        ('is_superuser', models.BooleanField(help_text='Designates that this user has all permiss
ions without explicitly assigning them.', verbose_name='superuser status', default=False)),
        ('email', models.EmailField(verbose_name='email address', unique=True, max_length=255, db
_index=True)),
        ('is_staff', models.BooleanField(help_text='Designates whether the user can log into this
 admin site.', verbose_name='staff status', default=False)),
        ('is_active', models.BooleanField(help_text='Designates whether this user should be treat
ed as active. Unselect this instead of deleting accounts.', verbose_name='active', default=True)),
        ('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.tim
ezone.now)),
        ('groups', models.ManyToManyField(related_name='user_set', to='auth.Group', help_text='Th
e groups this user belongs to. A user will get all permissions granted to each of their groups.', blank=T
rue, verbose_name='groups', related_query_name='user')),
        ('user_permissions', models.ManyToManyField(related_name='user_set', to='auth.Permission'
, help_text='Specific permissions for this user.', blank=True, verbose_name='user permissions', related_q
uery_name='user')),
    ],
    options={
        'abstract': False,
        'verbose_name': 'user',
        'swappable': 'AUTH_USER_MODEL',
        'verbose_name_plural': 'users',
    },
    ),
]
╭╴ (user-model-74=) [virt]╶╮
╰ [T] django@beta11:django $ 

1 个答案:

答案 0 :(得分:0)

事实证明custom_user必须在世界其他地方之前迁移,但sites甚至在custom_user之前迁移。所以这解决了我们的问题:

python manage.py migrate sites
python manage.py migrate custom_user
python manage.py migrate