Home >Database >Mysql Tutorial >Why Am I Getting MySQL Error 150: Foreign Key Constraint Issues?
MySql Error 150: Foreign Key Constraints
When executing queries to create two tables, one as a reference for the other, an error message indicates: "ERROR 1005 (HY000): Can't create table './test/bar.frm' (errno: 150)."
According to MySQL's FOREIGN KEY Constraints documentation, the error arises when a re-created table referenced by a foreign key constraint does not adhere to its definition. Specifically, the re-created table must:
In this case, the documentation suggests that the issue may be that one of the tables, 'foo', was not created as an InnoDB table. This is because foreign key constraints can only be established between InnoDB tables that are not TEMPORARY.
The documentation states:
Both tables must be InnoDB tables and they must not be TEMPORARY tables.
Therefore, to resolve the error, it is recommended to ensure that the 'foo' table is created as an InnoDB table before attempting to establish the foreign key constraint in the 'bar' table.
The above is the detailed content of Why Am I Getting MySQL Error 150: Foreign Key Constraint Issues?. For more information, please follow other related articles on the PHP Chinese website!