Blog

Blog

PHODAL

Django 1.8 解决 Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

在升级Django 到1.8 的时候遇到了这个问题

RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

后来找了找原因是因为在新版的Django中,表django_content_type已经没有name这个column。

所以需要把这个column删了,特别重要的事说很多遍。

注意: 开始前请备份数据库。

注意: 开始前请备份数据库。

注意: 开始前请备份数据库。

MySQL Django 1.8 Error creating new content types

注意: 开始前请备份数据库。

MySQL比较简单就执行

'ALTER TABLE django_content_type DROP COLUMN name'

SQLite3 Django 1.8 Error creating new content types

注意: 开始前请备份数据库。

由于SQLite3没有DROP COLUMN,所以需要如下的步骤

ALTER TABLE django_content_type RENAME TO content_type_old;

CREATE TABLE "django_content_type" (
"id" integer NOT NULL PRIMARY KEY,
"app_label" varchar(100) NOT NULL,
"model" varchar(100) NOT NULL,
UNIQUE ("app_label", "model")
);

INSERT INTO django_content_type(id, app_label,model)
SELECT id, app_label,model
FROM content_type_old;

DROP TABLE content_type_old;

当然如果不是特别重要的可以直接

 DROP TABLE  django_content_type

可能还需要

 python manage.py migrate  --fake

关于我

Github: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签