mysql stupid errors – ERROR 1005: Can’t create table {table name} (errno: 121)

Posted on July 21st, 2011 by thiswayup.
Categories: Development.

So I've spent at least half a day trying to figure out a stupid error when synching (creating) between my mysql workbench schema to a mysql database. I was receiving an error :

ERROR 1005: Can't create table {table name} (errno: 121)

I worked out that the issue was the foreign keys but had no idea why it was tripping out! Turns out that you need to name the actual foreign keys uniquely themselves. Therefore Ive taken to adding the table name in front of the foreign key name ie

BAD = "FK_title" if there is another table with the same foreign name, you'll get the above unhelpful message!

GOOD = "actor_FK_title" as you cant have two tables with the same name, you;re safe in the knowledge that you wont have a dupe FK.

0 comments.

Leave a comment

Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.