1

When i am trying to insert values in MySQL table through java code, I am getting the exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (icd_app_suite/mapper, CONSTRAINT FK_mapper_1 FOREIGN KEY (user_id) REFERENCES user_detail (user_id) ON DELETE CASCADE ON UPDATE CASCADE)

What can be the cause?

0

2 Answers 2

3

The error is clear: you're inserting (or updating) a row which doesn't respect a foreign key in referenced table.
So you first have to insert father record, then child record.
Probably you're adding a record on user_detail table with ID field not present in user table

Sign up to request clarification or add additional context in comments.

Comments

0

You are inserting a row with a value in the user_id column that is not found in the user_id column of the user_detail table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.