开发者

Adding index key in Grails' Domain

开发者 https://www.devze.com 2022-12-28 20:55 出处:网络
I tried following this reference and this is now my domain\'s code: class SnbrActVector { long nid String term

I tried following this reference and this is now my domain's code:

class SnbrActVector {

    long nid
    String term
    double weight

    static mapping = {
        version false
        nid index:'Nid_Idx'
    }

    static constraints = {
        term(blank:false)
    }
}

What I want is to d开发者_如何学运维o is to add an index key for the nid column. I dropped the existing table and ran the app again so the table is then recreated. However, when I check for list of indices, I can't see an Nid_Idx, only PRIMARY. Do I have to manually create the index and name it Nid_idx in my mysql database?


Yes, it's working only when using dbCreate = "create".

Let's say I have an empty database and my dbCreate set to "update". In this case index is not created.


Your syntax is correct so it might be another problem or a Grails bug. My advice :

  1. Create a new grails application (grails create-app) with SnbrActVector as the only domain (grails create-domain...). Copy your code inside.
  2. Check that your DataSource.groovy file has dbCreate = "create-drop"
  3. Verify the indices of the SnbrActVector table.

If you see an index created for nid column, then it means that there is problem in your application (you might not have used "create-drop" or something else)

If the index is NOT created => This is a grails bug and you should open a JIRA issue here


You might need to add the column name to get it to fire e.g.

static mapping = {
        version false
        nid column:'nid', index:'Nid_Idx'
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号