AbstractUser 模型的 django 1.8.5 迁移失败
django 1.8.5 migrations fail for AbstractUser model
我在将我的项目从 django 1.7.4 迁移到 1.8.5 时遇到了一个奇怪的问题
在我的项目中,我像这样扩展了基本的用户模型:
应用用户:
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 is migrated before trying to migrate apps individually.
您需要做的就是添加依赖项,这样您的迁移就会运行按顺序进行。
查看 django.contrib.contenttypes.migrations
,将最新的作为依赖项添加到 account.migrations
中,它应该一切正常。
我在将我的项目从 django 1.7.4 迁移到 1.8.5 时遇到了一个奇怪的问题
在我的项目中,我像这样扩展了基本的用户模型:
应用用户:
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 is migrated before trying to migrate apps individually.
您需要做的就是添加依赖项,这样您的迁移就会运行按顺序进行。
查看 django.contrib.contenttypes.migrations
,将最新的作为依赖项添加到 account.migrations
中,它应该一切正常。