关于 mysql:Magento:更新 1.4 -> 1.7 后外键约束失败

Magento: a foreign key constraint fails after update 1.4 -> 1.7

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or
update a child row: a foreign key constraint fails
(my_magento/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) O)

这是我尝试重新索引数据时遇到的错误(按照此处的建议输出它:"重新索引过程出现问题???。"产品导入后)

但那个解决方案根本没有帮助。请帮助在哪里搜索它,我对 MySQL 外键不是很熟悉。如何检测损坏的记录?修复它们的原则是什么?


您的一个产品引用了一个不存在的 category_id。通常在通过管理后端编辑内容时不应该发生这种情况。您是直接在数据库中删除了类别吗?

您必须检查哪个产品引用了该类别并删除该引用。类别和产品之间的引用存储在 catalog_category_product 中。 catalog_category_entity 中的类别。要查找行,您可以使用该查询:

1
2
3
SELECT * FROM catalog_category_product ccp
LEFT JOIN catalog_category_entity cce ON ccp.category_id = cce.entity_id
WHERE cce.entity_id IS NULL