Failing to Create Foreign Keys (errno 150) + Solution

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

If you are struggling to get some foreign keys set up on your MySQL InnoDB database then perhaps this is your problem and a pretty simple solution.

If you are getting errno 150 then take a look at the data types for the two fields that you are trying to relate to each other.

I had issues in Magento creating foreign keys against the customer_entity and sales_flat_order tables (entity_id columns). Turns out the issue was that these columns were set to UNSIGNED on the Magento tables, yet my tables columns did not have this attribute.

Set your columns to UNSIGNED (and otherwise double check the datatypes are the same) and I bet it will all work for you.


Tags: mysqlmagentoinnodbforeign keyserrno 150