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
, CONSTRAINTFK_mapper_1
FOREIGN KEY (user_id
) REFERENCESuser_detail
(user_id
) ON DELETE CASCADE 开发者_JAVA百科ON UPDATE CASCADE)
What can be the cause?
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
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
精彩评论