Django的1.8.5迁移失败AbstractUser模型
问题描述:
从Django的1.7.4迁移我的项目时1.8.5Django的1.8.5迁移失败AbstractUser模型
在我的项目我有一个奇怪的问题,我扩展了用户的基本模型,像这样:
App用户:
class User(AbstractUser):
age = models.IntegerField()
def __unicode__(self):
return self.username
现在在Django 1.8.5迁移因为某些原因我不得不这样做
python manage.py makemigrations
开始时
这将为用户应用程序进行迁移。
如果我以后做这
python manage.py migrate
直接就失败,此错误
django.db.utils.ProgrammingError: relation "users_user" does not exist
然后我做的:
python manage.py migrate users
从而未能
"Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure
contenttypes is migrated before trying to migrate apps individually.
有趣的是,即使失败了,现在正在运行
python manage.py migrate
作品
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles, django_extensions, allauth, avatar, crispy_forms, debug_toolbar
Apply all migrations: sessions, users, contenttypes, admin, sites, account, auth, socialaccount
Synchronizing apps without migrations:
Creating tables...
Creating table avatar_avatar
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying account.0001_initial... OK
Applying account.0002_email_max_length... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
Applying sites.0001_initial... OK
Applying sites.0002_set_site_domain_and_name... OK
Applying sites.0003_auto_20151104_1309... OK
Applying socialaccount.0001_initial... OK
从旧的Django版本迁移到1.8时,任何人都经历了同样的问题?
答
在试图单独迁移应用程序之前迁移contenttypes。
您需要做的就是添加依赖项,以便您的迁移按顺序运行。
看看django.contrib.contenttypes.migrations
,在account.migrations
中添加最新的依赖项,它应该都可以正常工作。
谢谢你,这是当场。但是现在我得到另一个错误,“关系django_site不存在”。但是这固定了我所问的问题。我将不得不看看另一个 – Donna
祝你好运:) - 我认为应该看的东西是:缺少的应用程序(contrib.something?),任何应用程序做一些有趣的代码检查/模型加载(如django调试工具栏)和依赖关系。 –