Last answered:

24 Jul 2020

Posted on:

24 Jul 2020

0

SQL INSERT Statement

I tried the insert statement exercise 1 but there was an error in the code which said: "Error code: 1452. Cannot add or update a child row: a foreign key constraint fails". The code i typed in look exactly the same as the solution 1 given so I'm not sure whats the problem
1 answers ( 0 marked as helpful)
Posted on:

24 Jul 2020

0
Hello Hui,   in the table, where you are inserting the data, are there any FOREIGN key constrains? Check DDL section in "table_you_are_inserting_into" information window.  If yes, check for which columns and the corresponding referenced table. If the value you are inserting is missing in the Referenced table, you will be unable to INSERT it in the corresponding column with FOREIGN key constraint.   Probably you are missing the value you are inserting in the Referenced table and maybe you just forgot to Insert it in the Referenced table first. See if you have employee 999903 in your employees table. Since you are probably inserting emp_no 999903 in the titles table.   You can try it and reply if it helped or the problem prevails.   Best regards, Maros J

Submit an answer