2

I get the following error when I try to reindex my Catalog URL Rewrites.

Product Attributes index was rebuilt successfully
Product Prices index was rebuilt successfully
Catalog URL Rewrites index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-hand-power-tools' for key 'UNQ_CATALOG_CATEGORY_ENTITY_URL_KEY_STORE_ID_VALUE'' in /var/www/html/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 /var/www/html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#5 /var/www/html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#6 /var/www/html/lib/Zend/Db/Adapter/Abstract.php(576): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#7 /var/www/html/app/code/core/Mage/Catalog/Model/Resource/Url.php(392): Zend_Db_Adapter_Abstract->insert('catalog_categor...', Array)
#8 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(301): Mage_Catalog_Model_Resource_Url->saveCategoryAttribute(Object(Varien_Object), 'url_key')
#9 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(320): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), 'hand-power-tool...', false)
#10 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(320): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), '/', false)
#11 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(461): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), NULL, false)
#12 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(254): Mage_Catalog_Model_Url->refreshCategoryRewrite('3', '1', false)
#13 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(248): Mage_Catalog_Model_Url->refreshRewrites('1')
#14 /var/www/html/app/code/core/Mage/Catalog/Model/Indexer/Url.php(257): Mage_Catalog_Model_Url->refreshRewrites()
#15 /var/www/html/app/code/core/Mage/Index/Model/Process.php(210): Mage_Catalog_Model_Indexer_Url->reindexAll()
#16 /var/www/html/app/code/core/Mage/Index/Model/Process.php(258): Mage_Index_Model_Process->reindexAll()
#17 /var/www/html/shell/indexer.php(166): Mage_Index_Model_Process->reindexEverything()
#18 /var/www/html/shell/indexer.php(212): Mage_Shell_Compiler->run()
#19 {main}

Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-hand-power-tools' for key 'UNQ_CATALOG_CATEGORY_ENTITY_URL_KEY_STORE_ID_VALUE'' in /var/www/html/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /var/www/html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /var/www/html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /var/www/html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /var/www/html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#4 /var/www/html/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#5 /var/www/html/lib/Zend/Db/Adapter/Abstract.php(576): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array)
#6 /var/www/html/app/code/core/Mage/Catalog/Model/Resource/Url.php(392): Zend_Db_Adapter_Abstract->insert('catalog_categor...', Array)
#7 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(301): Mage_Catalog_Model_Resource_Url->saveCategoryAttribute(Object(Varien_Object), 'url_key')
#8 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(320): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), 'hand-power-tool...', false)
#9 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(320): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), '/', false)
#10 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(461): Mage_Catalog_Model_Url->_refreshCategoryRewrites(Object(Varien_Object), NULL, false)
#11 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(254): Mage_Catalog_Model_Url->refreshCategoryRewrite('3', '1', false)
#12 /var/www/html/app/code/core/Mage/Catalog/Model/Url.php(248): Mage_Catalog_Model_Url->refreshRewrites('1')
#13 /var/www/html/app/code/core/Mage/Catalog/Model/Indexer/Url.php(257): Mage_Catalog_Model_Url->refreshRewrites()
#14 /var/www/html/app/code/core/Mage/Index/Model/Process.php(210): Mage_Catalog_Model_Indexer_Url->reindexAll()
#15 /var/www/html/app/code/core/Mage/Index/Model/Process.php(258): Mage_Index_Model_Process->reindexAll()
#16 /var/www/html/shell/indexer.php(166): Mage_Index_Model_Process->reindexEverything()
#17 /var/www/html/shell/indexer.php(212): Mage_Shell_Compiler->run()
#18 {main}
Category Products index was rebuilt successfully
Catalog Search Index index was rebuilt successfully
Stock Status index was rebuilt successfully
Tag Aggregation Data index was rebuilt successfully

How can I solve this?

1
  • Have you tried deleting the just the affected row in core_url_rewrite?
    – jscar
    Jul 11, 2017 at 10:06

3 Answers 3

2

Make a dump from you database: Step 1: On you ssh shell do this command:

mysqldump -h databasehost -u user -pPASSWORD databasename > filename.sql

Step 2: So you can try:

TRUNCATE core_url_rewrite;

And try reindex again.

This should do the trick.

12
  • 2
    This is basically telling people to delete all the rewrites of a Magento installation. Do you have anything to back up your answer? Are you sure that the rewrites will be automatically regenerated after?
    – mbalparda
    Aug 1, 2014 at 18:48
  • Yes im sure, already do that thousants of time. Sometimes we have old registrys on this table, the reindex process may broke. To guarantee we aways make a backup from database. I don't have sure this will solve the problem, but aways i have problem with rewrite truncate this table is aways a good solution. reindex process make all up right again.
    – Guerra
    Aug 1, 2014 at 18:49
  • This did not help. For some reason I cannot call TRUNCATE core_url_rewrite; My query is interrupted. Thanks though. Aug 1, 2014 at 19:54
  • I know u can be a little unconfortable truncating this table, but fore sure it will help you. Have absoluty no reason to don't work this command. Check it out. Or die trying ;)
    – Guerra
    Aug 1, 2014 at 20:00
  • 4
    This is awful. Please understand the implications of this before you truncate such an important table. That person who handles all your SEO might come knocking when valuable urls no longer work because all the custom url rewrites that may have been added in the admin suddenly vanish.
    – pspahn
    Mar 18, 2015 at 23:10
8

Do not truncate: core_url_rewrite

This is the worst advice ever, you will lose all customized SEO urls! Just dont do it!

What worked for me was SSH and running:

php -f ./shell/indexer.php -- -reindex catalog_url

If nothing else works then maybe attempt the table dropping idea, but only as a last resort!

1
  • Then what is the another solution
    – Gem
    Aug 4, 2016 at 6:13
1

I'm not certain why your truncate is getting interrupted, that's problematic. You can try rebuilding the index from the shell script from the main Magento directory:

php -f ./shell/indexer.php -- -reindex catalog_url

1
  • I have tried that. I get the same error. Aug 3, 2014 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.