Magento目录企业到社区降级期间的产品索引错误

时间:2014-02-13 22:03:54

标签: mysql magento indexing

我们正试图从Magento EE 1.13降级到CE 1.8.1。

我们正在使用新的CE代码库,但是尝试使用相同的数据库,我们理解这些数据库应该可以从以下主题开始: https://magento.stackexchange.com/questions/6706/how-to-migrate-from-enterprise-edition-to-community-edition

在删除我们找到的任何企业引用后,该网站运行良好,但我们无法解决的一个错误是索引错误:

exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magentodb`.`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 DE)' in /mnt/hgfs/public/lib/Zend/Db/Statement/Pdo.php:228

搜索此错误的大多数结果都建议尝试在catalog_category_product表中找到对不存在的产品的引用,这在外键约束失败的情况下有意义:

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);

但是这些查询返回空集 - 似乎没有对实体表中不存在的entity_ids的任何引用。

关于这可能来自哪里的任何建议?

3 个答案:

答案 0 :(得分:4)

  1. 转到PhpMyAdmin并运行此查询:

    ALTER TABLE catalog_category_product_index DROP FOREIGN KEY FK_CAT_CTGR_PRD_IDX_PRD_ID_CAT_PRD_ENTT_ENTT_ID

  2. 从Magento管理面板或CLI运行重建索引;

  3. 重建索引完成后,从PhpMyAdmin:

    运行此查询

    catalog_category_product_index删除 product_id不在(从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)引用catalog_product_entityentity_id)ON DELETE CASCADE ON UPDATE CASCADE;

答案 1 :(得分:0)

重读该错误。小心

exception 'PDOException' with message 
'SQLSTATE[23000]: Integrity constraint violation: 
1452 Cannot add or update a child row: a foreign key constraint fails
(   `magentodb`.`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 DE)'

特别是他们引用表格的部分

`magentodb`.`catalog_category_product_index`, 

当索引代码尝试在catalog_category_product_index中插入或更新列时,外键约束失败。我会检查这张桌子是否干净。

答案 2 :(得分:0)

例外' PDOException'有消息

'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magentodb`.`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 DE)' in /mnt/hgfs/public/lib/Zend/Db/Statement/Pdo.php:228

这个错误我得到了解决方案。检查以下信息

以下是我们用于解决类别产品(索引类别/产品协会)重新索引问题的流程:

  1. 登录phpMyAdmin
  2. 转到catalog_category_product_index
  3. 点击“导出”。
  4. 仅启用导出“禁用外键检查”的结构。
  5. 删除表catalog_category_product_index
  6. 使用导出的SQL,删除约束 出口的底部。一定要保留“SET FOREIGN_KEY_CHECKS” 声明。
  7. 单击“SQL”,粘贴已修改的SQL并单击“开始”
  8. 登录Magento后端
  9. 转到:系统 - >指数管理
  10. 点击“类别产品”索引
  11. 旁边的“重新索引数据”
相关问题