I am getting the following error when I make an order with a credit/debit card in Magento:
Order saving error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '282-189' for key 2
I could not get an exact trace, as it just didn't want to show that to me, however, I have traced it back to app/code/core/Mage/Checkout/controllers/OnepageController.php
on line 501
(unedited). The exact line is:
$this->getOnepage()->saveOrder();
Now, logic tells me this is just two orders having the same key when trying to add an order, or am I completely wrong?
Anyway, so outside this, what is the best way to get this fixed? I have thought of exporting the orders, removing them all, and then reimporting them, but I've got the feeling it won't work.
I am using Magento 1.6.2.0
EDIT: I just realized, if I find out which table is failing the integrity check, I could potentially empty that table (depending on which table it is) and this would fix it self? Any ideas on how to find out which table is messing up?
EDIT2: So after Oğuz Çelikdemir's answer, it turns out the following is the culprit:
2012-03-14T13:59:01+00:00 DEBUG (7): SQL: INSERT INTO `sales_order_tax_item` (`tax_id`, `item_id`, `tax_percent`) VALUES (?, ?, ?) (254, 8, 10)
2012-03-14T13:59:01+00:00 DEBUG (7): SQL: INSERT INTO `sales_order_tax_item` (`tax_id`, `item_id`, `tax_percent`) VALUES (?, ?, ?) (254, 8, 10)
Obviously two of the same tax_id can't be inserted. Anyone any idea how to fix it?