Magento: Integrity constraint violation: 1452 Cannot add or update a child row


After installing Magento sample data with Magento 1.6.1.0 you might have issues with rebuilding indexes.

If you’re getting “There was a problem with reindexing process.” error and “Integrity constraint violation: 1452 Cannot add or update a child row” in your exception.log, it can be caused by missing table prefixes in Magento sample data dump.

Fortunately, there’s a way to fix it.

The actual error in the exeption log that can point to missing prefixes can look somewhat like this for Magento 1.6:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (magento.mage1610_cataloginventory_stock_status, CONSTRAINT FK_CATINV_STOCK_STS_PRD_ID_CAT_PRD_ENTT_ENTT_ID FOREIGN KEY (product_id) REFERENCES catalog_product_entity (entity_id) ON)

If you check the error carefully, you’ll notice that catalog_product_entity table is wrong and should be actually called mage1610_catalog_product_entity.

If you are using prefixes in your Magento installation, you should dump your database and check every corresponding operation for table prefixes. If it is indeed your issue, you should be able to fix it by adding all missing prefixes and importing your dump back in the database.

You might also want to use our Magento Sample Data Prefix Script to adapt Magento Sample Data for a prefixed Magento installation.

Martin Boze

Founder and Lead Everything at MultiMerch Marketplace.
Share on Facebook0Tweet about this on Twitter0Share on LinkedIn0Share on Google+0Share on Reddit0Share on StumbleUpon0
  • rajesh

    I am getting following error when submitting the product review form in magento

    SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
    (mymagento.review, CONSTRAINT FK_REVIEW_ENTITY_ID_REVIEW_ENTITY_ENTITY_ID FOREIGN KEY (entity_id)
    REFERENCES review_entity (entity_id) ON DELETE CASCADE ON UPDATE CASCADE)

  • shikha

    i have this type of error .. i solved
    change database table- change attribute_set_id 0 to as Default value- As defined: is 1 in catalog_product_entity …

  • http://blog.lib.umn.edu/heinz062/uthink-forum/2011/09/google-feedburner-available-for-umn-google-apps-users.html#comments Jones sabo but also congressmen

    I believe this web site holds some very wonderful info for everyone. “Anger makes dull men witty, but it keeps them poor.” by Francis Bacon.

  • http://batman-news.com sh4

    Helped a lot. I changed all the prefixes in a theme’s SQL dump example data except the REFERENCES sentences. Changed that and it’s working now. Thanks!