9

When I use the Grails Database Migration Plugin and run a dbm-gorm-diff (for example, after installing the Spring Security Facebook plugin) I have been getting problems like:

Error: Error executing SQL CREATE INDEX `FK609FD5A460CFCC39` ON `facebook_user`(`user_id`): Incorrect index name 'FK609FD5A460CFCC39'

It looks like the index in question is both a FK constraint and is then reused as an index later in the generated upgrade script. If i change the name, thus removing the duplicate, everything works fine. I am using Mysql. Am I doing something wrong?

Thanks.

4
  • Have you been using the plugin successfully up till now? Commented May 13, 2012 at 5:23
  • @David It is still pretty new to me. I tried a few basic upgrades and they worked. Commented May 13, 2012 at 13:33
  • I was just thinking if maybe you have dbcreate="..something.." in your DataSource.groovy file it might be conflicting with the plugin. But if you've done upgrades already that seems to be less likely. Commented May 15, 2012 at 9:14
  • Did anyone manage to solve that issue? I have the exact same issue right now and I can't figure out what is happening. Commented May 23, 2012 at 16:04

3 Answers 3

9

I just found out that if I edit changelog.groovy to place addForeignConstraint's after createIndex's, it works like a charm. Yet another problem in the changelog generation script I guess.

Sign up to request clarification or add additional context in comments.

1 Comment

Strange, this solution didn't work for me. I had multiple addForeignConstraints and multiple createIndexs. Changing the key did allow it to work though... don't know if that will have any adverse effects later.
2

I suspect this is actually related to MySQL and not to the plugin itself. See this bug: http://bugs.mysql.com/bug.php?id=55465

Sebastien's answer is a work around.

Comments

1

As per this question/answer, MYSQL automatically indexes foreign key columns. So when you add a foreign key constraint, you don't need to also define an index. I use the db migration plugin and just remove the 'index' entries for foreign keys that the dbm-gorm-diff generates.

I think this is a bit better than changing the name, since that likely creates more than one index on the same column which is just a waste of resources.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.