标题确实说明了一切 - 我在尝试重新索引类别产品时遇到 FK 约束失败。
完整的异常(exception)是:
There was a problem with reindexing process.SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
(`krcscouk`.`catalog_category_product_index`, CONSTRAINT `FK_CAT_CTGR_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE)
我以前在平板 table 上见过这种情况,但从未在类别产品上见过,而且我不确定我需要查看哪些 table 才能使其正常运行。
最佳答案
错误中有你的答案: FK_CAT_CTGR_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID
FK -> Foreign Key
CAT_CTGR_PRD_IDX -> Table Catalog_Category_Product_Index
PRD_ID -> Column Product_ID from the table above
CAT_PRD_ENTT -> Table Catalog_Product_Entity
ENTT_ID -> Column Entity_ID from the table above
因此,您的问题是从这些表之一到另一个表的外键失败。最有可能的是,您删除了产品并在 Catalog_Category_Product_Index 中留下了某些内容。在您的数据库上运行以下选择:
SELECT * FROM catalog_category_product_index WHERE product_id NOT IN (SELECT entity_id FROM catalog_product_entity)
从数据库中删除这些行,索引过程应该可以工作。
关于mysql - Magento - 尝试重新索引类别产品时的 FK_CAT_CTGR_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID 外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23568130/