0

On My site i am running old version of Advanced Product Options Suite Extension for Magento 2 by mageworx. I just updated the Advanced Product Options Suite Extension into latest version. I tired updation with upload Extension files manually also tried update Extension via composer also. On both case after i run bin/magento setup:upgrade command i am getting below error.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dqgdqtpdwx`.`#sql-73a8_365`, CONSTRAINT `MAGEWORX_OPTBASE_PRD_ATTRS_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE)

I tired to check on My Database but i cant found any table or data related to this error. Someone can help me to solve this issue ?

1 Answer 1

1

This is a MySQL error for tables that have foreign keys:

For storage engines that support foreign keys, MySQL rejects any INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no matching candidate key value in the parent table.

To decode your error, start from the right and work to the left.

First, your parent table is catalog_product_entity and the primary key is entity_id.

Second, your child table has a foreign key of product_id and is identified as MAGEWORX_OPTBASE_PRD_ATTRS_PRD_ID_CAT_PRD_ENTT_ENTT_ID. This latter value will be identified somewhere in MageWorkx's codebase, but you can usually figure it out just from the name if the developer followed Magento's naming conventions. In this case, the second half of the foreign key name represents the table and field of the parent table: CAT_PRD_ENTT stands for catalog_product_entity, and ENTT_ID stands for entity_id.

The first half is MAGEWORX_OPTBASE_PRD_ATTRS_PRD_ID. We already know the field in question is product_id, so that takes care of PRD_ID. This leaves us with the table, or MAGEWORX_OPTBASE_PRD_ATTRS. I don't know MageWorx's tables, but the name will very likely include some version of "product attributes."

So to summarize all that, you're looking for a MageWorx table that includes "product attributes" in its name, and the field that's causing you problems is the product_id which as a foreign key requires that there be a matching value in the entity_id field of catalog_product_entity.

The solution, then, to your problem is to identify records in your MageWorx table that are tied to product IDs (aka entity_ids) that no longer exist in catalog_product_entity. Purge those records from your MageWorx table, and you should be good to go.

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.