mysql - 由于 longblob,Grails 没有生成表格?

标签 mysql grails

我刚才被这个问题难住了。 Grails 没有创建我所拥有的必要表 在我的域中指定。这是结果 执行 grails run-app 后的命令行:

        [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table image 
(id bigint generated by default as identity (start with 1), 
version bigint not null, content longblob not null, 
content_type varchar(255), description varchar(255), 
name varchar(255), product_id bigint, size bigint not null, 
type varchar(255) not null, primary key (id))
    2011-11-06 16:25:31,142 [main] ERROR hbm2ddl.SchemaExport  - Wrong data type: 
LONGBLOB in statement [create table image (id bigint generated by default
 as identity (start with 1), version bigint not null, content longblob]

我相信这与我的领域类有关。有人能指出我正确的方向吗?我正在使用 grails 1.3.7,这是我的域类 Image.groovy。

class Image {

    static belongsTo = Product

    Product product

    ImageType   type

    String  name
    String  description
    byte[]  content
    String  contentType
    Long    size

    static constraints = {

        product     nullable: true
        content     nullable: false
        contentType nullable: true, blank: true
        size        min: 0L
        name        nullable: true, blank: true
        description nullable: true, blank: true

    }

    static mapping = {
        content (sqlType: "longblob")
    }


}

我很惊讶,因为静态映射可以与我的其他 grails 应用程序一起使用。所以它可能是别的东西。

最佳答案

使用sqlType 将立即使您依赖于数据库。它适用于知道 longblob 的数据库,但对于不知道这种类型的数据库会失败。相反,您可以用更一般的方式解释 GORM,即您的数据比平时更长:

private static final MAX_IMAGE_SIZE = 1073741824 // 4GB 

static constraints = {
    content(maxSize:MAX_IMAGE_SIZE)
}

这样做的最大好处是,如果数据库知道,GORM 会将类型映射到 longblob,否则它将映射到 LOB 或其他类似的:所以它是独立于数据库的.

关于mysql - 由于 longblob,Grails 没有生成表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8025976/

相关文章:

sql - 如何从 grails 调用数据库函数?

grails - Grails Controller 中使用动态mixins进行异常处理

grails - Grails-指定 Controller 时滤镜不触发

grails - 将 groovy 数组传递给 javascript 代码

MySQL 和从 CSV 导入小数

mysql - 如何从mysql表的副本中获取修改后的值

mysql - 您如何获得每个特定计数分组的记录百分比

grails - Grails/安全性:实现NonAuthFilter的动机

mysql - Rails - 第一个应用程序 Mysql 错误

mysql - 想要获得 Laravel 时间范围内的结果