2011-11-13 70 views
0

我已将版本从版本1.4.0.1升级到版本1.6。 我已经删除了网站上的所有产品,并做了“重新索引全部”,成功完成。 当我尝试创建一个新的产品,比再做一个重新索引我得到这个错误:升级到版本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,但它并没有帮助。

我该如何解决这个问题?

+1

如果你正在做的和重大的升级和删除所有的产品可能是简单的重新开始,并导入客户。 – clockworkgeek

+0

我有很多服装属性和CMS内容需要很长时间来复制。可悲的是,它看起来并不像magento提供这种信息的导出和导入。 – Shani1351

回答

0

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

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) 

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

+0

是否会从商店中删除实时数据? –

+0

sql查询所说的是'删除文本或删除产品不再存在于主产品表中的数字',所以是删除数据,但删除数据时无论如何索引时都会导致约束问题。它有点像胳膊和腿没有任何身体漂浮。让我们摆脱那些事情。 – JaseC

15

这只会删除不应该在那里的流氓数据。

我已经扩大了上面的,因为它可以节省挖的几个小时:

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

我发现这也有助于为FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID约束错误'DELETE PF1。* FROM PF1 catalog_product_flat_1 LEFT JOIN catalog_product_entity P于pf1.entity_id = p.entity_id WHERE ISNULL(p.entity_id)' – JaseC

+0

这就是我一直在寻找很长一段时间。谢啦! – Ross