2013-12-13 46 views
1

我不能使用南,我沒有pgAdmin,但我需要在模型的末尾添加新字段到模型。我需要的是:django添加模型字段manualy到postgres數據庫

new_field = models.CharField(max_length=200, blank=True, null=True) 

我有ssh訪問,並有PSQL用戶定義的,所以我需要的語法到該字段添加到模型數據庫表。 ALTER TABLE store_products ADD COLUMN description text;是否能完成這項工作?如何設置max_length 200,空白和空值爲true? postgresql 9.1,django 1.6。

+0

爲什麼不能用南方? http://south.readthedocs.org/en/latest/ – crazyzubr

回答

3

我把blank=Truenull=True表示應該允許空字符串和NULL值。這些是默認設置,你不需要做任何額外的事情。

對於max_length=200可以使用varchar(200),而不是text

ALTER TABLE store_products ADD COLUMN description varchar(200); 

但我一般喜歡在組合中的數據類型textCHECK constraint

ALTER TABLE store_products ADD COLUMN description text; 
ALTER TABLE store_products ADD CONSTRAINT description_max200 
CHECK (length(description) <= 200); 
+0

謝謝Erwin – Goran