0

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

使用 django-custom-user,我了解到我必须先对 custom_user 进行迁移,然后才能进行剩余的迁移。很公平。在一个干净的实例上(刚刚创建了一个数据库并 git clone'd 代码),我输入

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

但是...不,我缺少 custom_user_emailuser。我怀疑这意味着 custom_user 与 key emailuser 的关系,但我仍然发现自己很难理解这是从哪里来的,所以该怎么做。非常感谢任何提示。

╭╴ (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 $ 
4

1 回答 1

0

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

python manage.py migrate sites
python manage.py migrate custom_user
python manage.py migrate
于 2015-05-28T11:49:09.570 回答