小编Zee*_*han的帖子

添加外键但出现约束冲突错误

我有四张桌子:

1)Country:Two columns
  a) country_id
  b) country_name

2)State: Three columns
  a) state_id
  b) state_name
  c) country_id(foreign key)

 3)City: Three Columns
   a) city_id
   b) city_name
   c) state_id(foreign key)

 4) Doctor: 20 Columns
   a) doc_id (primary key)
   b) doc_name
   c) email,gender age and so on 
Run Code Online (Sandbox Code Playgroud)

我已经用 dara 填充了这些表。

我在 doctor 表中添加三个新列:country_id、state_id 和 city_id 作为外键。

当我将 Country_id、state_id 和 city_id 作为外键插入到该表中时,出现此错误

1452 - Cannot add or update a child row: a foreign key constraint fails (`medical_network`.`#sql-4174_45`, CONSTRAINT `#sql-4174_45_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) …
Run Code Online (Sandbox Code Playgroud)

mysql constraints foreign-keys

2
推荐指数
1
解决办法
1648
查看次数

标签 统计

constraints ×1

foreign-keys ×1

mysql ×1