2

MySQL is giving me grief when I try to recreate a particular table in a particular database; I believe the problem is that somewhere MySQL has some records of the table's foreign keys and keeps trying to check the constraint when I try to recreate the table.

The database in question is for the test environment and is periodically refreshed by dumping the prod DB, dropping the test DB, creating the test DB again and then applying the prod DB dump to the new test DB.

However last night when I went to do this procedure I suddenly ran into MySQL's errno: 121, which is normally related to an incorrect foreign key... If I try with a different table defnition, without specifying a key, I get errno: 150 instead. However, this only occurs if I try to apply the dump to a new database of exactly the same name as the old one. If I create a database with a different name from the old one (on the same server still) and apply the dump, there is no problem.

In fact, I can't even create a table of exactly the same name without any keys at all even in a completely new database.

This example demonstrates the problem

mysql> create database test_db;
Query OK, 1 row affected (0.01 sec)

mysql> connect test_db;
Connection id:    1590
Current database: test_db

mysql> create table client_feed_group(id int);
ERROR 1005 (HY000): Can't create table './test_db/client_feed_group.frm' (errno: 150)
mysql> create database new_db_name;
Query OK, 1 row affected (0.00 sec)

mysql> connect new_db_name;
Connection id:    1591
Current database: new_db_name

mysql> create table client_feed_group(id int);
Query OK, 0 rows affected (0.01 sec)

I have already dropped the test_db database; this should remove all table and all records. I then create it, connect to it and try to create the old table client_feed_group; I get an error. I create another database with a different name and follow the same steps; this time there is no problem.

2
  • Are there any other tables in the database, which could contain foreign key constraints referring to client_feed_group? perror 150 -> MySQL error code 150: Foreign key constraint is incorrectly formed
    – joschi
    Commented Oct 30, 2010 at 7:01
  • In my example above, there are no other tables in the database at all, and no foreign key being defined in my create table call - note that the first act above is to create the database, so it should be empty.
    – El Yobo
    Commented Oct 31, 2010 at 4:25

1 Answer 1

1

It appears to be the same as this MySQL bug.

The procedure located far down in the comments worked for me, that is

  • create the table again using the same schema as the old one, but using a MyISAM engine
  • use ALTER TABLE to change the engine to innodb

thereafter things appear to work correctly; I can now drop the database and do a full restore with no problems.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.