Adding a Foreign key on a MySQL Table

I recently had trouble adding a foreign key on a MySQL database.

ERROR 1005 (HY000): Can't create table '.\test\b.frm' (errno: 150)

After much searching I discovered that the problem was that the columnbeing references needed to be indexed.
So then adding a foreign key, make sure;

  • it is anĀ  InnoDB table
  • reference column may need to be identical in both tables.
  • column being referenced is indexed. (The error message is not clear on this at all.)

About Editor