Magento:更新后的外键约束失败1.4 - > 1.7 [英] Magento: a foreign key constraint fails after update 1.4 -> 1.7

查看:197
本文介绍了Magento:更新后的外键约束失败1.4 - > 1.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


SQLSTATE [23000]:完整性约束冲突:1452无法添加或
更新子行:外键约束失败
my_magento / catalog_category_product_index ,CONSTRAINT
FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID FOREIGN KEY
category_id )参考 catalog_category_entity entity_id )O)

这是我在尝试重新索引数据时得到的错误(按照这里的建议输出它:

<产品导入后的问题与重新索引过程 - 产品导入后的处理>但是这个解决方案根本没有帮助。请帮忙在哪里搜索它,我不是很熟悉MySQL的外键。如何检测损坏的记录?修正它们的原则是什么?

其中一个产品引用了不存在的category_id。通常这不应该发生在通过管理后端编辑的东西。您是否直接在数据库中删除类别?



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

pre code $ 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


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)

This is the error I'm getting when trying to reindex data (outputed it as it's adviced here: "There was a problem‍​​ with reindexing process." after product import )

But that solution doesn't help at all. Please help where to search for it, I'm not really familiar with MySQL foreign keys. How to detect corrupted records? What's the principe of fixing them?

解决方案

One of your products is referencing to a category_id which does not exist. Usually this should not happen when editing things through the admin-backend. Did you delete the category directly in the database?

You have to check which product is referencing the category and remove that reference. The references between category and product are stored in catalog_category_product. The categories in catalog_category_entity. To find the row you can use that query:

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 

这篇关于Magento:更新后的外键约束失败1.4 - &gt; 1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆