Django 1.8 OperationalError:没有这样的专栏

时间:2014-12-28 19:22:16

标签: django django-models django-database django-migrations django-1.8

我只是想在模型上添加一个字段。

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

谢谢

2 个答案:

答案 0 :(得分:0)

为什么要运行sqlmigrate?运行迁移的正确命令只是migrate

sqlmigrate只打印将在迁移中执行的SQL,如the documentation所示。

答案 1 :(得分:0)

您是否尝试在python manage.py makemigrationspython manage.py migrate之后运行python manage.py syncdb