Magento 拒绝重新索引我的产品目录。它正在记录此错误:
2013-01-29T23:24:51+00:00 DEBUG (7): Exception message: SQLSTATE[23000]:
Integrity constraint violation: 1452 Cannot add or update a child row:
a foreign key constraint fails (`cjsquash_mgnt1`.`catalog_category_product_index`,
CONSTRAINT `FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`))
我认为这意味着 catalog_category_product_index 中有一个无效行,在 catalog_category_entity 表中缺少值,但我运行了这个查询:
SELECT *
FROM catalog_category_product_index
where category_id not in (select entity_id from
catalog_category_entity)
它返回 0 行,因此看起来并非如此。我该怎么做才能解决这个问题?
最佳答案
我在仔细考虑之后自己弄明白了这一点 - 问题来自于索引过程想要在 catalog_category_product_index 表中插入一行,其中 product_id 或 category_id 不存在。这就是导致违规的原因。
如果在此步骤中失败的索引处理随后运行一个查询来确定是哪些行导致了问题,那就太好了,但在此之前,您可以运行这两个查询,它们将告诉您是哪个 product_id 或 category_id 导致了问题问题。这两个查询都应返回 0 条记录。如果他们返回一条记录,您将确切地知道哪个产品属于不存在的类别或哪个类别具有不存在的产品。你可以
SELECT * FROM `catalog_category_product` WHERE
product_id not in (select entity_id from catalog_product_entity)
SELECT * FROM `catalog_category_product` WHERE
category_id not in (select entity_id from catalog_category_entity)
然后您可以删除有问题的行,或者更谨慎地编辑有问题的产品或类别并重新保存其类别或产品,以便将良好的数据输入到问题表中。然后索引将起作用。
关于mysql - Magento 和重新索引目录上的错误 1452(违反完整性约束),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14594063/