Grails GORM MySQL生成TEXT或LONGTEXT列

时间:2022-05-03 06:49:19

I am using Grails 2.1.1 and MySQL 5.5.27 Community Server.

我正在使用Grails 2.1.1和MySQL 5.5.27社区服务器。

I need to have a Domain class field generate a TEXT or LONGTEXT column.

我需要有一个Domain类字段来生成TEXT或LONGTEXT列。

I thought this would be simple, and I've seen numerous examples:

我觉得这很简单,我见过很多例子:

Grails domain class, String field TEXT and LONGTEXT

Grails域类,字符串字段TEXT和LONGTEXT

How can grail generate TEXT not LONGTEXT data type or column

如何生成TEXT而不是LONGTEXT数据类型或列

However, I've run into dead-ends all night. I followed all these examples and none seem to work (even though others have reported that it works).

但是,我整晚都遇到了死胡同。我遵循了所有这些例子,似乎都没有工作(即使其他人报告它有效)。

Here is a sample Domain Class I created:

以下是我创建的域类示例:

class Coltest {

    static constraints = {
        description1 sqlType: 'longtext'
        description2 sqlType: 'text'
        description3 type: 'text'
        description4 column: "longDescription", type: "text", nullable:true
    }

    String description1
    String description2
    String description3
    String description4
}

Here is what I get in MySQL command interface:

这是我在MySQL命令界面中得到的:

mysql> describe coltest;
+--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| id           | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| version      | bigint(20)   | NO   |     | NULL    |                |
| description1 | varchar(255) | NO   |     | NULL    |                |
| description2 | varchar(255) | NO   |     | NULL    |                |
| description3 | varchar(255) | NO   |     | NULL    |                |
| description4 | varchar(255) | YES  |     | NULL    |                |
+--------------+--------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

No matter what I try, I always seem to get a column of type varchar(255).

无论我尝试什么,我似乎总是得到一个varchar(255)类型的列。

Apologies if I'm missing something silly, but I've been staring at this all night, and think I've tried everything that others have reported to work.

抱歉,如果我错过了一些愚蠢的事情,但我一直盯着这一整夜,并且认为我已经尝试过其他人报告的所有工作。

Any insight would be appreciated tremendously. Thank you in advance.

任何见解都会受到极大的赞赏。先谢谢你。

1 个解决方案

#1


25  

I think that the issue is that 'sqlType' belongs in a mapping, not a constraint.

我认为问题在于'sqlType'属于映射,而不是约束。

Try either:

尝试:

static constraints = {
  description2 size: 1..5000
}

or

要么

static mapping = {
  description2 sqlType:"text"
}

#1


25  

I think that the issue is that 'sqlType' belongs in a mapping, not a constraint.

我认为问题在于'sqlType'属于映射,而不是约束。

Try either:

尝试:

static constraints = {
  description2 size: 1..5000
}

or

要么

static mapping = {
  description2 sqlType:"text"
}