Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails在更改表时生成错误_Grails_Sql Server 2012_Gorm_Grails Domain Class_Grails 2.3 - Fatal编程技术网

Grails在更改表时生成错误

Grails在更改表时生成错误,grails,sql-server-2012,gorm,grails-domain-class,grails-2.3,Grails,Sql Server 2012,Gorm,Grails Domain Class,Grails 2.3,我正在尝试将一个已经存在的PHP应用程序迁移到grails中 我已经在现有数据库的基础上创建了域,代码运行得非常好 当我需要在我的域中添加一个额外的布尔字段时,问题就出现了 我得到以下错误 2014-06-10 16:24:54,146 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate - Unsuccessful: alter table entry add expedite tinyint not null Error | 2014-0

我正在尝试将一个已经存在的PHP应用程序迁移到grails中

我已经在现有数据库的基础上创建了域,代码运行得非常好

当我需要在我的域中添加一个额外的布尔字段时,问题就出现了

我得到以下错误

2014-06-10 16:24:54,146 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate  - Unsuccessful: alter table entry add expedite tinyint not null

Error |
2014-06-10 16:24:54,163 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate  - ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'expedite' cannot be added to non-empty table 'entry' because it does not satisfy these conditions.
我尝试在变量本身中指定默认值

boolean expedite = false
我还尝试在静态映射中添加默认值,如下所示:

static mapping = {
    table 'entry'
    expedite defaultValue: false
    version false
}

但还是出现了错误。知道我哪里出错了吗?我正在使用sql server 2012。

看起来sql server使用的是0和1,而不是TRUE/FALSE。这就是你要找的吗

另一个人就是这样解决的


看起来您只需要在域中创建一个方法来拦截和转换。

因为默认情况下mysql将布尔字段映射为一位值,所以布尔字段的值不能为空

通过以下方式手动更新现有记录:

update my_table set expedite = 0;
也可以使用grails数据库迁移插件为您生成迁移

域类中的任何基元数据类型都会获得默认值,因此,如果您将定义新字段,如
布尔值
,则它可以使用空值


因此,请始终确保使用基本数据类型和非基本数据类型。

尝试使用类,而不是基本数据类型:布尔加速

是否可以使加速为空?如果你能做到这一点,下一个代码可能是解决方案:静态约束={procedute nullable:true}我确实尝试过这个,但仍然得到相同的错误。即使使用布尔类,我也会得到相同的错误。此问题仅在使用sql server 2012时出现。在mysql中不会出现这种情况。是否可能已经在表中创建了字段?你正准备绘制地图。如果是这样,请手动删除字段,并让grails使用类声明再次为您创建字段。否,此字段不存在于任何其他表中。已在SQL Server 2005上尝试。得到了同样的例外。如果约束有:expediate(nullable:true),它就可以工作。我的问题是无法手动更新表。我需要用gorm来做。即使使用非基本数据类型,此问题仍然存在。使用sql server 2012而不是mysql时也会出现此问题。