The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

Error Code 1452: Cannot add or update a child row (INSERT statement exercise)

Error Code 1452: Cannot add or update a child row (INSERT statement exercise)

Super Learner

I tried to run the INSERT INTO statement exercise, but I got the error code 1452 appear. Does anyone else have the same problem? And how do i fix it?
The error still appeared even when i tried to copy the code from the solution into MySQL. Really appreciate if anyone can help.
Thank you

1 Answer

365 Team

Hi Thu!
Thanks for reaching out.
We’ve answered this question here:
But here’s the answer for your convenience.
Please stick to our general request to execute all code you see in the lectures and the exercises, in the given order. Doing this will prevent you from encountering some errors, such as this one – Error Code: 1452.
This error appears if you have already created another table, employees, where you have missed inserting data about the individual with id 999903. The relationship you have established between employees and dept_emp requires that you first insert a record in employees, and then insert a (related) record in dept_emp.
ON DELETE CASCADE means that if you remove record 999903 from employees, record 999903 will automatically be removed from dept_emp as well.
In brief, make sure the relationship between employees and dept_emp is valid and 999903 exists in employees so that you don’t get the same error the next time you try inserting 999903 in dept_emp.
SOLUTION: As explained in the article preceding this video, double-check if you’ve first inserted information about employee number 999903 in the employees table. Only then you should proceed with inserting information in the titles and dept_emp tables.

Hope this helps.

I got it. Thank you so much for your answer. I really appreciate for your time and your dedicate to this course. This is one of the best course i have had for SQL. It is very detail & easy to understand. Hat off to 365 team 🙂

10 months

Thank you very much for these very kind words, Thu! Your comment is the first I read today, and you really made my day! Good luck and please feel free to post another question should you encounter any other difficulty. Thank you. 🙂

10 months
Complete Data Science Education
Get 50% OFF