升级到1.6版后无法重新索引新产品

时间:2011-11-13 13:33:16

标签: php magento

我已将我的网站从版本1.4.0.1升级到版本1.6。 我删除了网站上的所有产品,并成功完成了“全部重新索引”。 当我尝试创建新产品而不是再次重新索引时,我收到此错误:

Product Attributes index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`.../catalog_product_index_eav`, CONSTRAINT `FK_CAT_PRD_IDX_EAV_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CAS)' in .../lib/Zend/Db/Statement/Pdo.php:228

我试过TRUNCATE TABLE catalog_product_index_eav,但没有帮助。

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:16)

这只会删除不应该存在的恶意数据。

我扩展了上述内容,因为它可以节省几个小时的挖掘时间:

delete FROM `catalog_product_entity_datetime` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_decimal` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_group_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_int` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_media_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_text` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_tier_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_varchar` where entity_id not in (select entity_id from catalog_product_entity);
#originals with formatting fixed:
delete from `catalog_category_product` WHERE product_id not in(select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity); 
delete from `catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity);

答案 1 :(得分:1)

我使用以下查询来清理目录表;

delete from `catalog_category_product` WHERE product_id not in(select entity_id from catalog_product_entity)

delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity) 

delete from ` catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity) 

delete from ` catalog_product_entity_media_gallery` WHERE entity_id not in(select entity_id from catalog_product_entity) 

delete from ` catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity) 

delete from ` catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity) 

delete from ` catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity) 

delete from ` catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity)

在此之后我能够从管理面板重新索引。

答案 2 :(得分:0)

如果您在实际站点上执行此操作,则可能需要在关闭Apache的情况下从命令行执行reindex过程。

http://overlycaffeinated.com/2011/02/when-reindexing-in-magento-fails-use-the-command-line/

这解释了如何做到这一点。