I am getting this error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (
university.registration, CONSTRAINTregistration_ibfk_2FOREIGN KEY (section_id) REFERENCESSection(section_id))
This is my code
INSERT INTO Registration VALUES (24766, 1102, 'B', 'B');
CREATE TABLE Registration (
student_id INT,
section_id INT,
midterm_grade VARCHAR(5),
final_grade VARCHAR(5),
PRIMARY KEY (student_id, section_id),
FOREIGN KEY (student_id)
REFERENCES Student (student_id),
FOREIGN KEY (section_id)
REFERENCES Section (section_id)
);
Any help would be appreciated on fixing this problem.
This is a common error in MySQL, most likey caused by either that
student_id24766does not exist in theStudenttable, orsection_id1102does not exist in theSectiontable.The fix is to simply make sure that your foreign keys in the
Registrationtable point to actual primary keys of records in the other two tables. So, you may need to insert some data to resolve this error.