2

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

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

谢谢

4

2 回答 2

0

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

sqlmigrate如文档所示,只需打印将在迁移中执行的 SQL 。

于 2014-12-28T20:20:10.887 回答
0

您是否尝试过跑步python manage.py makemigrations,然后呢python manage.py migratepython manage.py syncdb

于 2015-06-01T20:02:17.507 回答