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
超详细!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 原因及解决方法
3987 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
185 0
Incorrect table definition; there can be only one auto column and it must be defined as a key
|
SQL Oracle 关系型数据库
SQL FOREIGN KEY Constraint on CREATE TABLE
SQL FOREIGN KEY Constraint on CREATE TABLE
93 1
|
SQL 关系型数据库 MySQL
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】
745 0
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】
|
关系型数据库 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
1487 0
|
关系型数据库 MySQL 数据库
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
287 0
[Err] 1143 - SELECT command denied to user 'XX'@'%' for column 'XXX' in table 'XX'
|
关系型数据库 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
274 0
|
SQL
ORA-02292: integrity constraint (xxxx) violated - child record found
在更新表的主键字段或DELETE数据时,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 这个是因为主外键关系,下面借助一个小列子来描述一下这个错误: SQL> create table studen...
2413 0