我是MySQl的新手,当我收到此错误时想要用密钥连接两个表。我浏览了一些相关的问题,但我似乎无法找到问题所在。
首先我创建了这个表并且它可以工作:
CREATE TABLE uniquepeps (ID INT NOT NULL, Sequence CHAR(30)
NOT NULL, PRIMARY KEY (Sequence));
LOAD DATA LOCAL INFILE "D://...//Uniquepeps.txt" INTO TABLE uniquepeps;
该表看起来像这样并起作用:
1 AAAATTTTTGGGGGG
2 GGGGGUUUUUKKK
3 OOOOPPPPMMMNN
然后我创建了另一张表:
CREATE TABLE peps (ID INT NOT NULL, Sequencepeps CHAR(30)
NOT NULL, PROTID INT NOT NULL, PRIMARY KEY (ID), CONSTRAINT
Seq_fk FOREIGN KEY (Sequencepeps) references uniquepeps(Sequence));
但是,当我尝试加载数据时,它没有工作,我收到了错误
LOAD DATA LOCAL INFILE "D://...//Pepsandprots.txt" INTO TABLE peps;
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`biology`.`peps`, CONSTRAINT `Seq_fk` FOREIGN KEY (`Sequencepeps`) REFERENCES `uniquepeps` (`Sequence`) )
第二个表的数据是:
1 AAAATTTTTGGGGGG 1
2 AAAATTTTTGGGGGG 2
3 AAAATTTTTGGGGGG 3
4 AAAATTTTTGGGGGG 4
5 GGGGGUUUUUKKK 1
6 GGGGGUUUUUKKK 8
7 OOOOPPPPMMMNN 9
8 OOOOPPPPMMMNN 25
感谢任何帮助!
答案 0 :(得分:0)
错误表示您尝试在表Sequencepeps
中的peps
中插入一个值uniquepeps
Sequence
列uniquepeps
。
仔细观察,您可以看到输入文件可能存在问题,在GGGGGUUUUUKKK
中您已写入peps
,但在GGGGGUUUUUKKK
- 文件中,您有两个不同的类似文件一个:GGGGUUUUUKKK
(这是正确的)和G
(缺少一个{{1}}) - 也许这是你身边的拼写错误?