我用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我不知道我做错了什么。我在另一台机器上使用了相同的脚本,它运行得很好。
发布于 2013-09-13 14:41:49
外键保持数据完整性,并在没有父行的情况下防止插入。您需要先填充descType父表。
https://stackoverflow.com/questions/18785403
复制相似问题