mysqlimport:错误:1452

时间:2013-09-13 11:37:42

标签: mysql perl foreign-keys mysqlimport

我在Perl中编写了一个创建数据库模式的脚本:

CREATE TABLE descType (
    id MEDIUMINT unsigned PRIMARY KEY,
    descr MEDIUMTEXT)ENGINE=InnoDB;

CREATE TABLE taxType (
    id MEDIUMINT unsigned PRIMARY KEY,
    descr TEXT not null)ENGINE=InnoDB;

CREATE TABLE uniref(
            id INT unsigned PRIMARY KEY,
            seqId varchar (50) not null,
            descId MEDIUMINT unsigned not null,
            n MEDIUMINT unsigned not null,
            taxId MEDIUMINT  unsigned not null,
            repId varchar (50) not null,
            foreign KEY (descId) REFERENCES descType(id),
            FOREIGN KEY (taxId) REFERENCES taxType(id),
            unique(seqId)
            )ENGINE=InnoDB; 

当我使用此命令时:

system qq(mysqlimport -u$mySqlUser -p$mySqlPass $database $table --local --fields-terminated-by="\t" --lines-terminated-by="\r\n") )== 0
   or die "ERROR: an error occurred while importing $table in $database. $?";

我收到此错误:

mysqlimport: Error: 1452, Cannot add or update a child row: a foreign key 
constraint fails (`uniref_2013_08`.`uniref`, CONSTRAINT `uniref_ibfk_1` 
FOREIGN KEY (`descId`) REFERENCES `descType` (`id`)), when using 
table: uniref

我无法弄清楚我做错了什么。我在另一台机器上使用相同的脚本,它工作正常。

1 个答案:

答案 0 :(得分:0)

外键保留数据完整性,并在没有父行时阻止插入。您需要先填充descType父表。