SQLSTATE: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ab6cbeda_tots`.`catalog_product_entity_varchar`, CONSTRAINT `CAT_PRD_ENTT_VCHR_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DEL), query was: INSERT INTO `catalog_product_entity_varchar` (`attribute_id`,`store_id`,`value`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)
Does anyone happen to have this kind of issue? Adding new product was working just fine before, until we migrated the site to new server and we have that error when adding new product.
Please let me know if someone knows how to fix it.
To fix this, first check that this is indeed the issue. Backup your database and then run the following SQL to see if any product and/or category associations are incorrect:
# Determine incorrect product associations SELECT * FROM `catalog_category_product` WHERE product_id not in (select entity_id from catalog_product_entity); # Determine incorrect categories SELECT * FROM `catalog_category_product` WHERE category_id not in (select entity_id from catalog_category_entity);
If that returns a record, you'll know exactly which product is in a non-existent category or which category has a non-existent product. Run the following SQL to then remove those invalid records:
# Delete incorrect product associations DELETE FROM `catalog_category_product` WHERE product_id not in (select entity_id from catalog_product_entity); # Delete incorrect categories DELETE FROM `catalog_category_product` WHERE category_id not in (select entity_id from catalog_category_entity);
Now log back into Magento Admin and reindex the Category Products index.
If issue resolve, please click on 'Kudos' & Accept as Solution!
Please check your attribute Id exists in database table or not, it seems attribute id deleted but exists in another table.
Or for temp fix by this you can add products
After that you can again do
Please take note this is not recommended solution but it will work for temp.