我在项目中使用grails 1.2.2和1.3.7。
我想向域表中添加索引。
class Test {
String name
String surname
static mapping = {
name column: 'name', index: 'test_dx'
surname column: 'surname', index: 'test_dx'
}
}
我尝试了两种版本的grails,并尝试使用dbCreate =“create”或dbCreate =“create-drop”或dbCreate =“update”(是我要使用的版本),但是没有创建“自定义索引”。
最佳答案
您的示例对我有用。如果我使用MySQL数据库以update
模式运行我的应用程序,则可以从MySQL控制台获取此信息:
mysql> show index from test;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| test | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | |
| test | 1 | test_dx | 1 | name | A | 0 | NULL | NULL | | BTREE | |
| test | 1 | test_dx | 2 | surname | A | 0 | NULL | NULL | | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)
您正在使用什么数据库?
关于database - Grails将域字段添加为数据库索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8447149/