Fixing “Duplicate entry” 1062 Errors in catalogrule_product

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

  1. Back up the catalogrule_product table.
  2. Truncate it. The data is generated, so the indexer will rebuild it.
  3. Run the reindex from the command line, not the admin, to avoid timeouts.
  4. 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.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.