Home >Database >Mysql Tutorial >Why Am I Getting MySQL Error 150: Foreign Key Constraint Issues?

Why Am I Getting MySQL Error 150: Foreign Key Constraint Issues?

Susan Sarandon
Susan SarandonOriginal
2024-11-27 17:20:14968browse

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:

  • Have the correct column names and types
  • Have indexes on the referenced keys

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn