Monday, October 01, 2007

MySQL Foreign Key Problem (errno: 150)

If you have this problem the following error message and you are just trying to import a dump from other machine, maybe I can offer you a tip. The error message is

ERROR 1005: Can't create table (errno: 150)

So, in this case, try to add the following to the top of your dump file:

set foreign_key_checks = 0;

It will disable, during the import session only, foreign key checks. Otherwise, mysql will complain when trying to create the first table that has a foreign key that refers to a table not yet created. It's a very useful tip when migrating databases (and that sometimes we forget).

2 comments:

huynh said...

I encounter this err 'cause i am new to mysql. Plz tell me where is the dump file?thanks you.

sugiarto said...

thanks. it lot help me :)