Question

After upgrading magento from 1.4.0.1 to 1.5.1.0, i'm not able to submit an invoice. When i'm pointing my browser to Sales -> Orders -> [order] View -> Invoice and click Submit invoice, i'm getting the error saying Unable to save the invoice.

I've checked what's going on in my exception.log file and here is the error:

exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '100000001' for key 'UNQ_INCREMENT_ID'' in /home/misbhv/domains/*/public_html/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /home/misbhv/domains/*/public_html/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/misbhv/domains/*/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /home/misbhv/domains/*/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `sk...', Array)
#3 /home/misbhv/domains/*/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(337): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `sk...', Array)
#4 /home/misbhv/domains/*/public_html/lib/Zend/Db/Adapter/Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `sk...', Array)
#5 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(414): Zend_Db_Adapter_Abstract->insert('sklep_sales_fla...', Array)
#6 /home/misbhv/domains/*/public_html/app/code/core/Mage/Sales/Model/Mysql4/Order/Abstract.php(417): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Order_Invoice))
#7 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Sales_Model_Mysql4_Order_Abstract->save(Object(Mage_Sales_Model_Order_Invoice))
#8 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Model/Resource/Transaction.php(150): Mage_Core_Model_Abstract->save()
#9 /home/misbhv/domains/*/public_html/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php(272): Mage_Core_Model_Resource_Transaction->save()
#10 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Adminhtml_Sales_Order_InvoiceController->saveAction()
#11 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('save')
#12 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#13 /home/misbhv/domains/*/public_html/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#14 /home/misbhv/domains/*/public_html/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#15 /home/misbhv/domains/*/public_html/index.php(80): Mage::run('', 'store')
#16 {main}

I have no idea what to do with that and 'm not able to google any solution. Any help would be much appreciated!

Was it helpful?

Solution

The solution from: http://www.magentocommerce.com/boards/v/viewthread/234665/#t335407 makes sense:

i had the same error code. the increment number and the last order number are not synchrone anymore. what we did is the following:

go to admin->sales-> orders and look up the highest order number (for each store view!)

after some help from a fooman post, we did this: \"Then look at your database. In the table eav_entity_type you will find all entity types listed. The one of interest to change is where the order number starts, ie. order sales/order. Remember the entity_type_id.\” (in my install it is 4)

\"Next go to the table eav_entity_store. Look up the entity_type_id. Now you can change the value of increment_last_id to your last actual order number. (That is, if you wanted to have your next orderId to be 15000 set increment_last_id to 14999.)\”

Hope that this helps.

OTHER TIPS

I actually looked at the solution above and thought it might work, you're on the right track but I tried something different:

Changing the 'increment_last_id' field solved no problem straight away - there was actually a set of orders existing from a previous store view that was deleted that shared the same order ID's so when Magento was trying to write the ID it failed in a duplicate error.

I found the problem by looking at my exception.log (it actually told me the order ID that was causing the problem).

Deleting those orders and re-aligning the new orders via editing the increment_last_id field solved my problem. Now my new orders start from the number above where they were last time and no order ID's clash anymore.

i think that you have a new restriction to unique in a row that in version 1.4.x don´t have required. You should see the duplicate row and solve create a new row with all the cascade constrains with another diferent increment_id. You can see duplicate rows with the next sql statement:

SELECT row FROM table GROUP BY row HAVING COUNT(*)>1;

later you need see the duplicate row, in my case i can remove the duplicate jey because those are a errors. is probaby that you can remove the rows duplicate because this is injured by an error in you Magento. In my case the magento scrip update stoped in whet try update the structure of the table.

I had an issue with the Fooman plugin and a blank space before all the increment_id's. This query fixed it for me ..

UPDATE `sales_flat_invoice` SET increment_id = trim(increment_id);
UPDATE `sales_flat_order` SET increment_id = trim(increment_id);
UPDATE `sales_flat_invoice_grid` SET increment_id = trim(increment_id);
UPDATE `sales_flat_order_grid` SET increment_id = trim(increment_id);
UPDATE `sales_flat_shipment` SET increment_id = trim(increment_id);
UPDATE `sales_flat_creditmemo` SET increment_id = trim(increment_id);
UPDATE `sales_flat_shipment_grid` SET increment_id = trim(increment_id);
UPDATE `sales_flat_creditmemo_grid` SET increment_id = trim(increment_id);
UPDATE `eav_entity_store` SET increment_last_id = trim(increment_last_id);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top