我不明白为什么我会犯这个错误:

integrity constraint (LEETO14.SYS_C00414504) violated - parent key

找不到
在currentloan的insert值之前,一切正常。这是我的代码:
CREATE TABLE Book
(bookID INT PRIMARY KEY,
ISBN INT,
title varchar (20),
author  varchar (20),
publish_year INT,
category varchar(20));

CREATE TABLE Member
(memberID INT PRIMARY KEY,
lastname varchar (20),
firstname varchar (20),
address varchar(20),
phone_number INT,
limit_ INT);

CREATE TABLE CurrentLoan
(memberID INT,
bookID INT,
loan_date DATE,
due_date DATE,
PRIMARY KEY (memberID, bookID),
FOREIGN KEY (memberID) REFERENCES Member(memberID),
FOREIGN KEY (bookID) REFERENCES Book(bookID));

INSERT INTO Book VALUES (10, 1113312336, 'The Dog', 'Jack Crow', 1990, 'fiction');
INSERT INTO Book VALUES (12, 2221254896, 'Worms', 'Jim Kan', 2013, 'fiction');
INSERT INTO Book VALUES (13, 3332546987, 'Crow', 'Jan Flo', 2000, 'fiction');
INSERT INTO Book VALUES (14, 4443456215, 'Big Dog', 'Lan Big', 1993, 'fiction');
INSERT INTO Book VALUES (15, 5552314569, 'Green Apple', 'Theo Brown', 1978, 'fiction');
INSERT INTO Book VALUES (16, 6664581631, 'Red Bean', 'Khang Nk', 2017, 'fiction');
INSERT INTO Book VALUES (17, 7771452369, 'The Dark Car', 'Author Le', 2017, 'fiction');
INSERT INTO Book VALUES (18, 8881245525, 'The Dark Room', 'Jack Se', 2017, 'fiction');
INSERT INTO Book VALUES (19, 9991123546, 'Lonely Mens', 'Geen Brown', 2014, 'fiction');
INSERT INTO Book VALUES (20, 1122112356, 'The Big Tree', 'Heart Le', 2002, 'fiction');

INSERT INTO Member VALUES (001, 'Lee', 'Nancy', 'Brownlea Drive', 1254896325, 2);
INSERT INTO Member VALUES (002, 'Le', 'Ray', '10th Street', 1234561256, 2);
INSERT INTO Member VALUES (003, 'Kan', 'Charlie', '5th Street', 1234567236, 2);
INSERT INTO Member VALUES (004, 'Brown', 'Joe', 'Elm Street', 1234567845, 2);
INSERT INTO Member VALUES (005, 'Smith', 'John', '33 East', 1234567890, 2);

INSERT INTO CurrentLoan VALUES (00123, 0236, '13-SEP-17', '14-NOV-17');
INSERT INTO CurrentLoan VALUES (00134, 2350, '13-JAN-17', '15-NOV-17');
INSERT INTO CurrentLoan VALUES (00125, 2034, '14-FEB-17', '12-MAR-17');
INSERT INTO CurrentLoan VALUES (00345, 0105, '12-OCT-17', '09-NOV-17');
INSERT INTO CurrentLoan VALUES (00311, 5012, '13-APR-17', '12-MAY-17');
INSERT INTO CurrentLoan VALUES (00213, 2051, '11-JUN-17', '02-OCT-17');

最佳答案

答案不言而喻。表中有外键,currentloan。查看insert语句,您正在尝试为尚未创建的成员和未创建的图书添加贷款。

关于mysql - 违反完整性约束(LEETO14.SYS_C00414504),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46373766/

10-11 01:39