ERROR 1215 (HY000): Cannot add foreign key constraint

简介: ERROR 1215 (HY000): Cannot add foreign key constraint

导致这个错误的原因可能有:

1.A表主建与B表外键数据类型、约束条件不一致。

2.两个数据表的存储引擎不一致。

3.两个表的字符集不一致。

...

我的错误:

1ecd1b2606ed46e9956a89f231c9802c.png

在建B表时无法添加外键。

1ecd1b2606ed46e9956a89f231c9802c.png

原因:我所使用的MySQL版本数据表的存储引擎是InnoDB,我在做练习的时候把主表的存储引擎改成了MyISAM。

1ecd1b2606ed46e9956a89f231c9802c.png

解决:改回来即可。

1ecd1b2606ed46e9956a89f231c9802c.png

建表成功。

相关文章
|
关系型数据库 MySQL 数据库
View ‘information_schema.SCHEMATA‘ references invalid table(s) or column(s) or function(s) or define
View ‘information_schema.SCHEMATA‘ references invalid table(s) or column(s) or function(s) or define
211 0
|
存储 关系型数据库 MySQL
超详细!Mysql错误1452 - Cannot add or update a child row: a foreign key constraint fails 原因及解决方法
超详细!Mysql错误1452 - Cannot add or update a child row: a foreign key constraint fails 原因及解决方法
3071 0
超详细!Mysql错误1452 - Cannot add or update a child row: a foreign key constraint fails 原因及解决方法
|
数据库
Incorrect table definition; there can be only one auto column and it must be defined as a key
Incorrect table definition; there can be only one auto column and it must be defined as a key
166 0
Incorrect table definition; there can be only one auto column and it must be defined as a key
|
关系型数据库 MySQL 数据库
MySQL问题解决:Cannot delete or update a parent row: a foreign key constraint fails
MySQL问题解决:Cannot delete or update a parent row: a foreign key constraint fails
1185 0
|
关系型数据库 MySQL
Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
220 0