django 1.8 迁移内容类型完整性错误

Ian*_*ick 1 django django-migrations

我将我的项目从 django 1.6 升级到 1.8。迁移时,我收到 contenttype 错误:

django.db.utils.IntegrityError: null value in column "name" violates not-null constraint
Run Code Online (Sandbox Code Playgroud)

详细信息:失败的行包含(31、null、django_auth、adgroup)。

我尝试迁移 contenttype 0002 但它告诉我:

django.db.utils.ProgrammingError: relation "django_content_type" already exists
Run Code Online (Sandbox Code Playgroud)

我如何克服第一个迁移文件?

DrM*_*ers 5

看起来您可能在应用程序中错误地进行--fake0002_remove_content_type_name迁移contenttypes

contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
Run Code Online (Sandbox Code Playgroud)

您可以使用以下方法撤消该操作:

./manage.py migrate contenttypes 0001 --fake
Run Code Online (Sandbox Code Playgroud)

然后正确运行0002迁移,以便从contenttypes表中删除 name 列:

./manage.py migrate contenttypes
Run Code Online (Sandbox Code Playgroud)

然后再次尝试为您的应用运行迁移。