ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing index for constraint 'orderite

ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing index for constraint ‘orderitem_ibfk_1’ in the referenced table ‘orders’

MySQL报这个错时去检查外键设置!!!这个外键是不是另外一个表的主键

设置外键的时候需要注意以下几点:
(1)外键是用于两个表的数据之间建立连接,可以是一列或者多列,即一个表可以有一个或多个外键。

(2)这个表里面设置的外键必须是另外一个表的主键!

(3)外键可以不是这个表的主键,但必须和另外一个表的主键相对应(字段的类型和值必须一样)。

(4)带有主键的那张表称为父表,含外键的是子表,必须先删除外键约束才能删除父表。

原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/13616896.html