I'm having the following exception on EE 1.13.1

Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxxxxxx' for key '5B1C775075460366570ABDA2839BC68A' in /lib/Zend/Db/Statement/Pdo.php:234

It looks something goes wrong with the Category Rules index:

  1. According to the exception information the issue starts from app/code/core/Enterprise/TargetRule/Model/Resource/Index/Abstract.php(213)
  2. key 5B1C775075460366570ABDA2839BC68A is actually an index of this table enterprise_targetrule_index_related

Any Idea ?
I'm actually debugging the above issue and I will share more info if I find something.


I have provided a solution below. It will be great if someone with more experience can confirm if try catch is fine ( usually it is not advisable to use try catch in the business logic ) or transaction is better.


Line 213 that trigger the exception is the one that try to do the INSERT

An initial SELECT check if a record with $targetruleId exist, if not Magento try to INSERT it. In some occasion (maybe because some concurrent access to the same page) a record is created, just after the select, just before the insert ...

If you need a official fix Magento has has patch for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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