简体   繁体   中英

Cannot add or update a child row: a foreign key constraint fails

i am having a user table which has desname as FK referring to des table ,i am trying to add desname in user but i am gettng Cannot add or update a child row: a foreign key constraint fails error.

desname is prepopulated and i am selected the same for he user.Where i am doing wrong I ma using mysql and hibernate hbm

The most common occurrence of this error is failing to create (and store) the required instance of the entity referenced by the foreign key. This generally occurs when the create operation for the parent entity is omitted, out of order, or in cases where the parent isn't correctly stored in the database prior to attempting creation of your weak entity.

For the record, this specific error message is only emitted when Hibernate attempts to write to the (MySQL) database it's connected to. Example code would significantly help here for solving your individual problem, as pointed out in the comments.

For everyone else interested, SO offers plenty of information for this particular error: https://stackoverflow.com/search?q=Hibernate+foreign+key+constraint+fails

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM