2011-11-13 101 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