Fixing “Duplicate entry” 1062 Errors in catalogrule_product
This error stops catalog price rule indexing in Magento, and it often appears after interrupted reindexes or rule imports:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry query was: INSERT INTO `catalogrule_product` (`rule_id`,`from_time`,`to_time`,`website_id`,`customer_group_id`,`product_id`,`action_operator`,`action_amount`,`action_stop`,`sort_order`,`sub_simple_action`,`sub_discount_amount`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),
The fix
- Back up the
catalogrule_producttable. - Truncate it. The data is generated, so the indexer will rebuild it.
- Run the reindex from the command line, not the admin, to avoid timeouts.
- If anything goes wrong, restore the table from your backup.
If it keeps happening, check that two reindex jobs are not running at the same time through cron.
Want this done for you? Find out more about our Magento development service.