爲了學習這個強大的工具,我正在用grails開發一個個人項目。Grails使用not null而不是null來改變我的表格
class Post {
long id;
Date creationDate;
String text;
byte[] image;
Style style;
long likeCount;
long dislikeCount;
User owner;
//coordinates on the wall
int x;
int y;
//this is probably to remove
static hasMany = [judgment : Judgment];
static constraints = {
text(nullable:true, maxSize:5000);
image(nullable:true, maxSize:1000000);
creationDate(nullable:true);
x(nullable:true);
y(nullable:true);
}
}
我增加x和y我在我的Postgres數據庫中創建一些數據(後記錄)之後: 增加了兩個新的領域(X,Y)到我的域類「郵報」的時候我也遇到了這個問題。 但是,當我運行的應用程序在Grails的安慰這個錯誤出現:
| Error 2012-03-04 12:04:23,670 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate - Unsuccessful: alter table post add column x int4 not null
| Error 2012-03-04 12:04:23,672 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate - ERROR: column "x" contains null values
這是很奇怪的,因爲我在約束聲明X,Y爲可以爲空..所以爲什麼Grails的嘗試改變我的表聲明x和Ÿ不是空?
你是非常正確的,非常感謝!你認爲總是使用非原始值更好嗎?假設我必須更改數據庫模式並添加新字段。使用非基元類型應避免此問題,因爲它們將默認爲現有記錄的空值。 – Giuseppe 2012-03-05 08:53:58