I am using Grails 2.1.1
and MySQL 5.5.27 Community Server
.
I need to have a Domain class field generate a TEXT or LONGTEXT column.
I thought this would be simple, and I've seen numerous examples:
Grails domain class, String field TEXT and LONGTEXT
How can grail generate TEXT not LONGTEXT data type or column
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> 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).
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.
I think that the issue is that 'sqlType' belongs in a mapping, not a constraint.
Try either:
static constraints = {
description2 size: 1..5000
}
or
static mapping = {
description2 sqlType:"text"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With