5

I just finish a website which include a cart. I'm using the commerce module.

In the development stage I've been making some test. Now I just deleted all these testing order, but now the id of the next order is something like 189. I need to put this number to 1.

Which database table do I need to truncate to get it done?

2 Answers 2

6

The commerce order module defines two tables, commerce_order and commerce_order_revision; you should truncate both of those to clear the data and reset the AUTO_INCREMENT counter.

In MySQL:

TRUNCATE TABLE commerce_order
TRUNCATE TABLE commerce_order_revision

Or using the API:

db_truncate('commerce_order');
db_truncate('commerce_order_revision');
1
  • 5
    Note that you must only do this after manually deleting all orders through Drupal's user interface. Otherwise you will be left with stale field values, line items and so on which will result in Exceptions when you attempt to save a new order with an id that has left over data.
    – Berdir
    Commented Mar 7, 2012 at 22:00
1

Some additional thoughts regarding resetting the entire "order" environment back to the first order...

In addition to truncating the commerce_order and commerce_order_revision tables after manually deleting through the admin interface as indicated above you should should determine if the following tables exist and need to be deleted (if you are using the contributed modules).

commerce_invoice - if using Invoice module

commerce_paypal_ipn - if using PayPal modules

commerce_payment_transaction - if using PayPal modules

commerce_payment_transaction_revision - if using PayPal modules

I ran into issues when these tables where not reset/truncated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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