Can’t create table (errno: 150)
This is not the first or the second time that I spend time digging this
fucking error whie creating a foreign key in Mysql.
This error code is telling you that your constraint is failing, possible due to some issues:
- table referenced doest not exist/not created yet
- column type from
REFERENCESis different then the on you are using
- foreign key name is duplicated
- This is common when we are copy and pasting some other sql from other tables, check this one!
Double check these issues and you can solve your problem.
If you to be more hard-core
Set Mysql to ignore the constrain checks by doing:
SET foreign_key_checks = 0; --> YOUR_SQL SET foreign_key_checks = 1;
Remembering that this option is not the best one, because you are ignoring checks, be aware of that.