Tag Archives: MySQL

Mysql errno: 150 when creating a foreign key

If you receive a errno; 150 when creating a foreign key in mysql, you may have encountered one of following problems :

  • The type of your foreign key is not the same as the referencing key, e.g. BIGINT -> INT
  • One of the two tables does not have the InnoDB engine. You cannot add foreign keys to MyISAM tables, or referencing MyISAM tables.

If you need more info about the actual error that occured, you can execute following sql statement :


This will show you which foreign key gave the error (or about other errors for that matter) and some more info about possible causes.

Disabling foreign keys in MySQL

Sometimes you want to perform some action on your database which needs foreign keys to be disabled. Luckily this is very easy in MySQL :

SET FOREIGN_KEY_CHECKS=0; # disable all foreign keys

# ... perform your sql magic

SET FOREIGN_KEY_CHECKS=1; # enable all foreign keys

Amazium.be blog about PHP and MySQL

For very specific and detailed info about PHP and MySQL related stuff, go to the Amazium blog. It is maintained by Jeroen Keppens (a former collegue of mine).