【发布时间】:2015-02-25 02:31:20
【问题描述】:
我只是想在模型上添加一个字段。
class Categories(models.Model):
#this IDUnique = models.IntegerField(max_length=11, blank=True, null=True)
IDParent = models.IntegerField(max_length=11, blank=True, null=True)
Name = models.CharField(max_length=45, blank=False)
当我尝试迁移时:
Operations to perform:
Synchronize unmigrated apps: formtools, social_auth, crispy_forms, django_comments
Apply all migrations: sessions, admin, sites, auth, appname, contenttypes
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
No migrations to apply.
删除并再次迁移并尝试sqlmigrate
BEGIN;
CREATE TABLE "appname_category__new" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "IDParent" integer NULL, "Name" varchar(45) NOT NULL, "IDUnique" integer NULL);
INSERT INTO "appname_category__new" ("Name", "id", "IDParent") SELECT "Name", "id", "IDParent" FROM "appname_category";
DROP TABLE "appname_category";
ALTER TABLE "appname_category__new" RENAME TO "appname_category";
COMMIT;
还是说
no such column: onlinemarket_categories.IDUnique
谢谢
【问题讨论】:
-
Django 1.8 尚未发布。现在坚持使用 1.7.x。
标签: django django-models django-database django-migrations django-1.8