gpt4 book ai didi

即使存在引用,MySQL 外键错误

转载 作者:行者123 更新时间:2023-11-29 03:12:37 26 4
gpt4 key购买 nike

在发帖之前,我已经对这个问题进行了一些搜索。这是问题所在:

mysql> insert into Buyer values (5594, CURDATE(), 490, 4830);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`oppminer`.`buyer`, CONSTRAINT `FK3D9119337C53076` FOREIGN KEY (`office_id`) REFERENCES `Office` (`id`))

我已确认引用的行存在:

mysql> select * from Office where id = 490;
+-----+-----------+-----------+-------------+-------------------+
| id | name | agency_id | location_id | primaryContact_id |
+-----+-----------+-----------+-------------+-------------------+
| 490 | Top Level | 88 | 7363 | 451 |
+-----+-----------+-----------+-------------+-------------------+
1 row in set (0.00 sec)

这是表的描述:

| Buyer | CREATE TABLE `Buyer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created` datetime DEFAULT NULL,
`office_id` bigint(20) DEFAULT NULL,
`primaryContact_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK3D9119337C53076` (`office_id`),
KEY `FK3D911938ADC7080` (`primaryContact_id`),
CONSTRAINT `FK3D911938ADC7080` FOREIGN KEY (`primaryContact_id`) REFERENCES `Contact` (`id`),
CONSTRAINT `FK3D9119337C53076` FOREIGN KEY (`office_id`) REFERENCES `Office` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5595 DEFAULT CHARSET=latin1 |
+-------

| Office | CREATE TABLE `Office` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`agency_id` bigint(20) DEFAULT NULL,
`location_id` int(11) DEFAULT NULL,
`primaryContact_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK8C9C2ADC3FBD3FD6` (`agency_id`),
KEY `FK8C9C2ADCFF56D2BF` (`location_id`),
KEY `FK8C9C2ADC8ADC7080` (`primaryContact_id`),
CONSTRAINT `FK8C9C2ADC8ADC7080` FOREIGN KEY (`primaryContact_id`) REFERENCES `Contact` (`id`),
CONSTRAINT `FK8C9C2ADC3FBD3FD6` FOREIGN KEY (`agency_id`) REFERENCES `Agency` (`id`),
CONSTRAINT `FK8C9C2ADCFF56D2BF` FOREIGN KEY (`location_id`) REFERENCES `Location` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=491 DEFAULT CHARSET=latin1 |
+--------

我还调查了表索引:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
110503 12:32:12 Transaction:
TRANSACTION 17A89, ACTIVE 0 sec, OS thread id 4493770752 inserting
mysql tables in use 1, locked 1
1 lock struct(s), heap size 376, 0 row lock(s), undo log entries 1
MySQL thread id 17, query id 31610 localhost root update
insert into Buyer values (5594, CURDATE(), NULL, 4830)
Foreign key constraint fails for table `oppminer`.`buyer`:

CONSTRAINT `FK3D911938ADC7080` FOREIGN KEY (`primaryContact_id`) REFERENCES `Contact` (`id`)
Trying to add to index `FK3D911938ADC7080` tuple:
DATA TUPLE: 2 fields;
0: len 8; hex 80000000000012de; asc ;;
1: len 4; hex 800015da; asc ;;

But the parent table `oppminer`.`Contact`
or its .ibd file does not currently exist!

我有两台机器,我将同一个转储恢复到其中。在正常工作的机器上,我可以成功地执行在有问题的机器上导致错误的相同命令。任何想法,堆栈溢出?

最佳答案

在最近发布的(5 月 31 日)MySQL 5.5.13 中也得到了修复:
MySQL 5.5 foreign key constraint fails when foreign key exists

关于即使存在引用,MySQL 外键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5874916/

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