MySQL Error 121 During CREATE TABLE

23 Nov 2009

I’m using MySQL to track a pile of data for a project at work. This is a one-off kind of thing that will probably be thrown away after I finish this project, but, I still try to make sure that I have a solid, yet simple, DB design. So, while iterating my way to having just the bits I need, I ran into:

$ >mysql -p database_name <filename.sql
Enter password: ***************
ERROR 1005 (HY000) at line 86: Can't create table database_name.table_name'(errno: 121)

A little Googling lead to several totally different explanations, which are things that I tried. What finally fixed it for me was the advice that I found at [ http://thenoyes.com/littlenoise/?p=81 ]. The SELECT statement for listing the foreign key names didn’t work on MySQL 5.1.40-community on Windows (yes, I know that 5.1.41 is out, I’ll get to it later). However, I did have a couple of tables that were using the same name for a foreign key pointing at the same third table. So, error 121 means a duplicate foreign key name somewhere in the database. Foreign key names must be unique across the entire database, not just within a given table.


Actions

Informations

2 responses to “MySQL Error 121 During CREATE TABLE”

14 06 2010
john (00:46:03) :

Hi can you give the steps on how you resolve this issue? I am experiencing the same error and I need to get this working asap. Any help is much appreciated!

15 12 2010
Philipp (05:37:21) :

Thank you very much!
I had the same problem while creating my DB, now i know where is the problem.
This is strange situation, that foreign keys must be uniqe in whole database…

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>