MySQL 外键约束

标签 mysql

我无法弄清楚这个错误:

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)

这是我正在尝试做的(来自日志):

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

我反复查看和查看表 computationid 的值以及该情况下的值:01 存在。

这有什么问题?

最佳答案

i just found out that the reference table is MyISAM not InnoDB will it affect?

是的。如 Using FOREIGN KEY Constraints 下所述:

The parent and child tables must use the same storage engine.

接着说:

For storage engines that do not support foreign keys (such as MyISAM), MySQL Server parses and ignores foreign key specifications.

关于MySQL 外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829616/

相关文章:

用于简单插入 MySQL 的 PHP PDO 安全程序

java - 不断从表数据库中获取内容

php - 如何使用 laravel eloquent 访问多个外键

php - 如何通过查询同一行中的另一个值来返回特定 mysql 单元格中的内容?

php - 更新数据库中的正确字段

php - 从表中获取相同字段的重复数据并比较同一表的其他字段

mysql - 错误代码 1093 :Error in Sql Syntax

mysql - SQL 通过带有 where 或子句的连接表进行选择

PHP 代码处理速度更快

用于变更检测的 MySQL 触发器