标题说明了一切 - 我在尝试重新索引类别产品时遇到了FK约束失败。
完全例外是:
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)
我之前看到它发生在平板电脑上,但从未出现在类别产品上,而且我不确定哪些表格我需要看一下才能让它很好地播放。
答案 0 :(得分:1)
错误有你的答案: 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)
从数据库中删除这些行,索引过程应该有效。
答案 1 :(得分:0)
转到PhpMyAdmin并运行此查询:
ALTER TABLE catalog_category_product_index DROP FOREIGN KEY FK_CAT_CTGR_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID
从Magento管理面板或CLI运行重建索引;
重建索引完成后,从PhpMyAdmin:
运行此查询DELETE FROM catalog_category_product_index WHERE product_id not in(从catalog_product_entity中选择entity_id); ALTER TABLE catalog_category_product_index ADD 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 CASCADE ON UPDATE CASCADE;