Jul 19 / Richard Knop

#1005 – Can’t create table ‘database_name.table_name’ (errno: 150)

When you are working with MySQL InnoDB table engine and especially foreign keys (as I do) you will encounter a similar error message quite often. Tracking down where exactly lies the problem can be very frustrating as the error message isn’t very suggestive.

From my experience, the problem is 99% of the time with foreign keys. Here are three most common reasons I have come across:

  • the two fields in the foreign key relationship are not exactly the same type (for example one is TEXT and another is VARCHAR)
  • although the two fields are the same type they aren’t the same size (for example one is INT(10) and another is INT(4))
  • the field you are referencing with the foreign key has no index (if the field is not a primary key you must add index to it)

I hope this might be helpfull to someone who comes across a similar error message.

Leave a Comment