Meenal Mishra
Meenal Mishra

Reputation: 49

MySql query exception

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?

Upvotes: 1

Views: 231

Answers (2)

Bohemian
Bohemian

Reputation: 425033

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

Upvotes: 0

Marco
Marco

Reputation: 57573

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

Upvotes: 3

Related Questions