简体   繁体   中英

Mysql cannot add or update child row, Foreign key related failure

Error: cannot add or update a child row: foreign key constraint fails

Following is the code that is creating the error:

ALTER TABLE 'catalog_eav_attribute' 
  ADD CONSTRAINT 'FK_CATALOG_EAV_ATTRIBUTE_ID' 
  FOREIGN KEY ('attribute_id') REFERENCES 'eav_attribute' ('attribute_id)' 
  ON DELETE CASCADE ON UPDATE CASCADE;

I uploaded the Structure of SQL and its has no issue , but when i insert the data i am getting the above related error. I read somewhere and i predict its because of lousy data.What are the other possibilities for the error ? Any suggestions or solution will be great.

"For storage engines other than InnoDB, MySQL Server parses the FOREIGN KEY syntax in CREATE TABLE statements, but does not use or store it."

From: http://dev.mysql.com/doc/refman/5.5/en/ansi-diff-foreign-keys.html

I'm not sure, but if your table is MyISAM and not InnoDB, your syntax might not work.

The error message means whatever number you're trying to put into the attribute_id column doesn't yet exist in the eav_attribute.attribute_id column.

Can you insert a value that does already exist in eav_attribute.attribute_id? (You probably can.)

Can you provoke the same error by trying to insert a value that doesn't exist in eav_attribute.attribute_id?

Reconcile the differences, and you're done. You need to determine which attribute ids don't exist in eav_attribute.attribute_id, and fix that.

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