title: Magento Order saving error: Integrity constraint violation
body: <p>I am getting the following error when I make an order with a credit/debit card in Magento:</p>
  
  <pre><code>Order saving error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '282-189' for key 2
  </code></pre>
  
  <p>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 <code>app/code/core/Mage/Checkout/controllers/OnepageController.php</code> on line <code>501</code> (unedited). The exact line is:</p>
  
  <pre><code>$this-&gt;getOnepage()-&gt;saveOrder();
  </code></pre>
  
  <p>Now, logic tells me this is just two orders having the same key when trying to add an order, or am I completely wrong?</p>
  
  <p>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.</p>
  
  <p>I am using Magento 1.6.2.0</p>
  
  <p>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?</p>
  
  <p>EDIT2: So after Oğuz Çelikdemir's answer, it turns out the following is the culprit:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Obviously two of the same tax_id can't be inserted. Anyone any idea how to fix it?</p>