0
我正面臨着表的默認值問題。Django Postgresql刪除列默認在遷移
例如我已經這種模式:
mydb=# \d model1
Table "public.model1"
Column | Type | Modifiers
--------+-----------------------+-----------------------------------------------------
id | integer | not null default nextval('model1_id_seq'::regclass)
field1 | character varying(50) | not null
field2 | character varying(10) | not null
Indexes:
"model1_pkey" PRIMARY KEY, btree (id)
遷移sqlmigrate的輸出爲::
class model1(models.Model):
field1 = models.CharField(max_length=50, default='My Default Value 1',db_column='field1')
field2 = models.CharField(max_length=10)
class Meta:
db_table = 'model1'
和PostgreSQL表而不默認生成
CREATE TABLE "model1" ("id" serial NOT NULL PRIMARY KEY, "field1" varchar(50) NOT NULL, "field2" varchar(10) NOT NULL);
COMMIT;
但如果我修改模型中的默認值並運行makemigrations/migrate,然後我考慮sqlmigrations輸出genereates一個奇怪的DROP DEFAULT創建
ALTER TABLE "model1" ALTER COLUMN "field1" SET DEFAULT 'My Default Value 1 modified';
ALTER TABLE "model1" ALTER COLUMN "field1" DROP DEFAULT;
COMMIT;
後有什麼我丟失或列的缺省值只是不支持?