Last Updated: February 25, 2016
· philippfrank

Magento, custom order numbers and the duplicate order id error

If you customize the order number format for your Magento installation to contain non-numeric characters you may experience the following behaviour: After an order was placed Magento is not able to retrieve a 'fresh' order number and report something like:

'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'MY-ORDER-001337' for key 'UNQ_SK24_SALES_FLAT_ORDER_INCREMENT_ID'' in /.../Zend/Db/Statement/Pdo.php:234

This is a bug in Magentos way to retrieve a new order number. To get rid of it just create a local copy of




and replace

$bind = array(':increment_id' => (int)$orderIncrementId);


$bind = array(':increment_id' => $orderIncrementId);

This way Magento is not trying to perform an integer type cast on your non-numeric order id.