简体   繁体   English

#1452-无法添加或更新子行:外键约束失败3

[英]#1452 - Cannot add or update a child row: a foreign key constraint fails 3

I want import data from excel to db. 我想将数据从Excel导入数据库。 I don't understand how to resolve this problem. 我不知道如何解决此问题。 I will be happy if you find out why this problem happens. 如果您找出发生此问题的原因,我将非常高兴。 Here is my SQL: 这是我的SQL:

CREATE TABLE IF NOT EXISTS `berobat` (
`id_berobat` int(11) NOT NULL AUTO_INCREMENT,
`tgl_berobat` date NOT NULL,
`id_pasien` int(11) NOT NULL,
`id_puskesmas` int(11) NOT NULL,
`id_penyakit` int(11) NOT NULL,
PRIMARY KEY (`id_berobat`),
KEY `id_pasien` (`id_pasien`),
KEY `id_puskesmas` (`id_puskesmas`),
KEY `id_penyakit` (`id_penyakit`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `berobat`
--

Mysql said : MySQL说:

#1452 - Cannot add or update a child row: a foreign key constraint fails (`dinkes`.`berobat`, CONSTRAINT `berobat_ibfk_1` FOREIGN KEY (`id_pasien`) REFERENCES `pasien` (`id_pasien`)) 

Your excel spreadsheet must have the rows related to the 'pasien' table come before the related rows in the 'berobat' table. 您的excel电子表格必须在“ berobat”表中的相关行之前具有与“ pasien”表相关的行。 Said another way, if you try to insert a row into the 'berobat' table that contains a value for the field 'id_pasien' that is not already stored in the 'pasien' table, then you will get this error. 换句话说,如果尝试在“ berobat”表中插入一行,但其中包含字段“ id_pasien”的值(尚未存储在“ pasien”表中),则会出现此错误。

So, you should be able to just sort your excel spreadsheet to have the 'pasien' table's rows on top, truncate your database tables to make sure they are clean and ready for a re-import, and then try again. 因此,您应该能够对excel电子表格进行排序,以使“ pasien”表的行位于顶部,截断数据库表以确保它们是干净的并准备重新导入,然后再试一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 1452无法添加或更新子行:外键约束失败 - 1452 Cannot add or update a child row: a foreign key constraint fails #1452-无法添加或更新子行:外键约束失败 - #1452 - Cannot add or update a child row: a foreign key constraint fails #1452-无法添加或更新子行:外键约束失败 - #1452 - Cannot add or update a child row: a foreign key constraint fails #1452 - 无法添加或更新子行:外键约束失败 - #1452 - Cannot add or update a child row: a foreign key constraint fails 1452 - 无法添加或更新子行:外键约束失败 - 1452 - Cannot add or update a child row: a foreign key constraint fails 错误1452:1452:无法添加或更新子行:外键约束失败 - ERROR 1452: 1452: Cannot add or update a child row: a foreign key constraint fails 错误:无法添加外键关系:#1452 - 无法添加或更新子行:外键约束失败 - Error: FOREIGN KEY relationship could not be added! #1452 - Cannot add or update a child row: a foreign key constraint fails SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败 - SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 违反完整性约束:1452无法添加或更新子行:外键约束失败 - Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails 违反完整性约束:1452无法添加或更新子行:外键约束失败 - Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM