gpt4 book ai didi

mysql - #1452 MySQL 错误 : foreign key constraint fails

转载 作者:行者123 更新时间:2023-12-01 00:23:31 25 4
gpt4 key购买 nike

这是两个数据库表:

1) kind_basis

id              bigint(20) unsigned     NO  PRI     NULL    auto_increment
vorname varchar(64) NO NULL
nachname varchar(64) NO NULL
geburtsland_id bigint(20) unsigned YES MUL NULL

2) liste_land

id              bigint(20) unsigned     NO  PRI     NULL    auto_increment
iso varchar(2) NO NULL
landname varchar(255) NO NULL

db-table liste_land 包含国家列表(摘录):

1   AD  Andorra
2 AE Vereinigte Arabische Emirate
3 AF Afghanistan
4 AG Antigua und Barbuda
5 AI Anguilla
6 AL Albanien
7 AM Armenien
8 AO Angola
....

这是sql查询:

 ALTER TABLE `kind_basis` 
ADD CONSTRAINT `fk_geburtsland_id`
FOREIGN KEY ( `geburtsland_id` )
REFERENCES `liste_land` (`id`)

这是 mysql 的错误信息:

#1452 - Cannot add or update a child row: a foreign key constraint fails
(`testing_v2.0.0`.<result 2 when explaining filename '#sql-6687_13b16'>,
CONSTRAINT `fk_geburtsland_id` FOREIGN KEY (`geburtsland_id`) REFERENCES
`liste_land` (`id`))

我做错了什么,但是什么?

最佳答案

在 kind_basis 表中,您有一行或多行带有 geburtsland_id,但在表 liste_land 的字段 ID 中没有匹配项。

关于mysql - #1452 MySQL 错误 : foreign key constraint fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19610989/

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