SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento_database`.`catalog_product_entity_media_gallery_value`, CONSTRAINT `FK_CAT_PRD_ENTT_MDA_GLR_VAL_VAL_ID_CAT_PRD_ENTT_MDA_GLR_VAL_ID` FOREIGN KEY (`value_id`) REFERENCES `catalog_produc)

I have scoured the internet but nothing seems to work. I have seen the Magento DB repair tool but I believe that would make things more complicated.

1 Answer 1


You are trying to update a row in catalog_product_entity_media_gallery_value, but the foreign key on catalog_product_entity (I guess) is missing.

Therefore you try to write a media gallery image, without having a product.

The solution for this is, to check why the entry in catalog_product_entity doesn't exist. Maybe the product_id value on your write to catalog_product_entity_media_gallery_value is null?

It is no problem with the defined foreign key, but with enforcing of this dependency.

Be careful when debugging this. This may all happen inside a transaction, then it is hard to look inside it - at least I don't know how to do this.

  • How do I restore the foreign key? ALTER TABLE catalog_product_entity_media_gallery_value ADD CONSTRAINT FK_CAT_PRD_ENTT_MDA_GLR_VAL_VAL_ID_CAT_PRD_ENTT_MDA_GLR_VAL_ID FOREIGN KEY (value_id) REFERENCES catalog_product_entity_media_gallery (value_id) ON DELETE CASCADE ON UPDATE CASCADE; didn't work either.
    – dac0507
    Oct 23, 2014 at 13:02
  • added more details. Oct 23, 2014 at 14:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.