Mysql 即使所有行都是InnoDB且存在外键,也无法添加或更新子行
在尝试插入记录时,我得到: 错误1452(23000):无法添加或更新子行:外键约束失败 涉及的两个表都是InnoDB。有问题的外键在另一个表中。字符集匹配。没有明显的原因Mysql 即使所有行都是InnoDB且存在外键,也无法添加或更新子行,mysql,key,constraints,Mysql,Key,Constraints,在尝试插入记录时,我得到: 错误1452(23000):无法添加或更新子行:外键约束失败 涉及的两个表都是InnoDB。有问题的外键在另一个表中。字符集匹配。没有明显的原因 CREATE TABLE `Client` ( `id` varchar(40) NOT NULL, `createdDate` datetime NOT NULL, `modifiedDate` datetime NOT NULL, `name` varchar(255) NOT NULL, `disa
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转储读取了它。这个问题逐渐消失了