gpt4 book ai didi

mysql - 即使所有都是 InnoDB 并且存在外键,也无法添加或更新子行

转载 作者:行者123 更新时间:2023-11-29 23:48:21 24 4
gpt4 key购买 nike

尝试插入记录后,我得到:

错误 1452 (23000):无法添加或更新子行:外键约束失败

涉及的两个表都是InnoDB。有问题的外键在另一个表中。字符集匹配。没有任何明显的原因存在。

CREATE TABLE `Client` (
`id` varchar(40) NOT NULL,
`createdDate` datetime NOT NULL,
`modifiedDate` datetime NOT NULL,
`name` varchar(255) NOT NULL,
`disabled` tinyint(1) NOT NULL DEFAULT '1',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `User` (
`id` varchar(40) NOT NULL,
`userName` varchar(255) DEFAULT NULL,
`clientId` varchar(40) NOT NULL,
PRIMARY KEY (`id`),
KEY `clientId` (`clientId`),
CONSTRAINT `user_ibfk_1` FOREIGN KEY (`clientId`) REFERENCES `client` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

select * from Client;
+--------------------------------------+---------------------+---------------------+------+----------+---------+
| id | createdDate | modifiedDate | name | disabled | deleted |
+--------------------------------------+---------------------+---------------------+------+----------+---------+
| 24d2e2da-933c-11e3-8665-e1550725a2bd | 2014-02-19 16:21:45 | 2014-02-19 16:21:45 | MWS | 0 | 0 |
+--------------------------------------+---------------------+---------------------+------+----------+---------+
1 row in set (0.00 sec)

INSERT INTO User (id,userName,clientId) VALUES ('eb124fde-8c85-11e3-894d-a29c2afd7657','ausername','24d2e2da-933c-11e3-8665-e1550725a2bd');
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`minerva_portal`.`User`, CONSTRAINT `user_ibfk_1` FOREIGN KEY (`clientId`) REFERENCES `client` (`id`))

我彻底迷失了。这是怎么回事?

最佳答案

显然在这种情况下,该错误是其他问题的幻影。我很沮丧,删除了数据库并从以前的 sql 转储中读取它。问题就消失了。

关于mysql - 即使所有都是 InnoDB 并且存在外键,也无法添加或更新子行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25797680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com