简体   繁体   English

MySQL外键约束

[英]MySQL Foreign Key Constraint

I can't figure out this error: 我无法弄清楚这个错误:

Cannot add or update a child row: a foreign key constraint fails ( freight . rates_detail , CONSTRAINT rates_detail_ibfk_2 FOREIGN KEY ( component_id ) REFERENCES computation ( id ) ON UPDATE CASCADE) 不能添加或更新子行,外键约束失败( freightrates_detail ,约束rates_detail_ibfk_2外键( component_id )参考computationid )ON UPDATE CASCADE)

Here's what I'm trying to do(from the log): 这是我想要做的(从日志中):

INSERT INTO freight.rates_detail(rate_id,component_id,uom,rate,inc_or) values(0821,01,00,011.00,'Y')

I repeatedly looked and looked and reviewed the values of id in table computation and the value in that case: 01 exists. 我反复查看并查看了表computationid值,在这种情况下,值:01存在。

What's the problem with this? 这是什么问题?

i just found out that the reference table is MyISAM not InnoDB will it affect? 我只是发现引用表是MyISAM而不是InnoDB会影响吗?

Yes. 是。 As documented under Using FOREIGN KEY Constraints : 使用外FOREIGN KEY约束中所述

The parent and child tables must use the same storage engine. 父表和子表必须使用相同的存储引擎。

It goes on to say: 它继续说:

For storage engines that do not support foreign keys (such as MyISAM ), MySQL Server parses and ignores foreign key specifications. 对于不支持外键的存储引擎(例如MyISAM ),MySQL Server会解析并忽略外键规范。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM