Home > Database > Mysql Tutorial > How to Fix MySQL Error 150: Foreign Key Mismatch?

How to Fix MySQL Error 150: Foreign Key Mismatch?

DDD
Release: 2024-11-26 16:01:17
Original
474 people have browsed it

How to Fix MySQL Error 150: Foreign Key Mismatch?

Troubleshooting MySQL Error 150: Foreign Key Mismatch

When attempting to create a foreign key constraint in MySQL, encounters can arise. One such error is Error 150, which occurs when there is a mismatch between the foreign key definition and the referenced table.

Error Description

Error Message:

ERROR 1005 (HY000): Can't create table './test/bar.frm' (errno: 150)
Copy after login

Possible Cause

As documented in the MySQL documentation on foreign key constraints, foreign key references require strict adherence to specific rules. One crucial requirement is that both the referencing table and the referenced table must be InnoDB tables.

Both tables must be InnoDB tables and they must not be TEMPORARY tables.
Copy after login

Solution

To resolve this error, verify that both the referencing table (bar) and the referenced table (foo) are defined as InnoDB tables. If they are not, alter them to use the InnoDB engine.

ALTER TABLE bar ENGINE=InnoDB;
ALTER TABLE foo ENGINE=InnoDB;
Copy after login

After making this change, attempt to recreate the foreign key constraint between the two tables. If the problem persists, consult the MySQL documentation again or seek assistance on relevant forums or from MySQL experts.

The above is the detailed content of How to Fix MySQL Error 150: Foreign Key Mismatch?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template