Reputation: 346
Our magento 1.6.2 cant not reindex product flat data. It also sometimes shows 'There was a problem with reindexing process.'
I tried many solutions from the experience of other users. No result. We imported bulk products but we are not sure it's the cause of reindexing problem.
What could be the ideal solutions?
This is the command i used in shell:
php /usr/local/lsws/fcgi-bin/lsphp5 /home/user/domains/my domain../public_html/shell/indexer.php
This is the error from exception.log
2012-08-09T14:55:43+00:00 DEBUG (7): Exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`galagearbox/#sql-1662_1fc419`, CONSTRAINT `FK_CAT_PRD_FLAT_4_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCA)
Trace: #0 /home/corecolu/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/corecolu/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/corecolu/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/corecolu/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/corecolu/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /home/corecolu/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /home/corecolu/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(327): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/corecolu/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(2548): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(4)
#10 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /home/corecolu/public_html/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /home/corecolu/public_html/app/code/core/Mage/Index/Model/Process.php(207): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /home/corecolu/public_html/app/code/core/Mage/Index/Model/Process.php(253): Mage_Index_Model_Process->reindexAll()
#14 /home/corecolu/public_html/app/code/core/Mage/Index/controllers/Adminhtml/ProcessController.php(124): Mage_Index_Model_Process->reindexEverything()
#15 /home/corecolu/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Index_Adminhtml_ProcessController->reindexProcessAction()
#16 /home/corecolu/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('reindexProcess')
#17 /home/corecolu/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /home/corecolu/public_html/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
#19 /home/corecolu/public_html/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#20 /home/corecolu/public_html/index.php(83): Mage::run('', 'store')
#21 {main}
Upvotes: 0
Views: 4562
Reputation: 1073
magento programatically re index ID Code
1 catalog_product_attribute
2 catalog_product_price
3 catalog_url
4 catalog_product_flat
5 catalog_category_flat
6 catalog_category_product
7 catalogsearch_stock
8 cataloginventory_stock
9 tag_summary
for ($i = 1; $i <= 9; $i++) {
$process = Mage::getModel('index/process')->load($i);
$process->reindexAll();
}
Upvotes: 0
Reputation: 1685
create one file like reindex.php in your magento root directory with following code
<?php
enter code here
// when you get status "Processing" instead of "Ready" in your index management run this script and it's working fine
// change the index order as per your requirement currently it's 7 for Catalog Search Index you can set as per your requirement
require_once 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
Mage::log("Started Rebuilding Search Index At: " . date("d/m/y h:i:s"));
$sql = "truncate catalogsearch_fulltext;";
$mysqli = Mage::getSingleton('core/resource')->getConnection('core_write');
$mysqli->query($sql);
$process = Mage::getModel('index/process')->load(7);
$process->reindexAll();
Mage::log("Finished Rebuilding Search Index At: " . date("d/m/y h:i:s"));
now save it and run it using browser and it will solved your problem
I hope you will get your solution. I will help you if you still getting problem.
Upvotes: 1
Reputation: 12727
Reindexing errors in Magento can have many reasons, so I'm afraid there never will be an "ideal" solution covering all possible errors.
Since you've posted a non-technical error message, I guess you've tried to reindex the product flat data using the admin backend and saw the error message there.
I'd recommend to try to reindex again, but using the shell/indexer.php
this time:
/usr/bin/php -f /abs/path/to/shell/indexer.php -- --reindex catalog_product_flat
This way you'll get more meaningful technical error messages, if reindexing fails.
Here's a list that shows which parameter to use for which index:
catalog_product_attribute Product Attributes
catalog_product_price Product Prices
catalog_url Catalog URL Rewrites
catalog_product_flat Product Flat Data
catalog_category_flat Category Flat Data
catalog_category_product Category Products
catalogsearch_fulltext Catalog Search Index
cataloginventory_stock Stock Status
tag_summary Tag Aggregation Data
The exception you've added to your post tells, that the referential integrity between
catalog_product_flat_4.entity_id
and
catalog_product_entity.entity_id
was found being corrupted.
Usually this means some record(s) contain(s) null
in the field catalog_product_entity.entity_id
, where they are expected to contain existing entity_id
s.
Before trying to fix this, please backup your database first.
Now, to find the corrupted record(s), query your database with:
SELECT
a.entity_id
FROM
catalog_product_flat_4 AS a
LEFT JOIN
catalog_product_entity AS b ON a.entity_id = b.entity_id
WHERE
ISNULL(b.entity_id)
The entity_id
s found by this query are entity_id
s in the table catalog_product_flat_4
, which are corrupted and need to be deleted.
Delete the appropriate records in catalog_product_flat_4
, and then try to reindex again.
Upvotes: 5