How do I set/reset the starting order number for my store?

Category: 
Developer
Topic: 
Site setup

Orders are numbered sequentially, starting at number "1" for a new installation of Ubercart. After testing your new installation you will probably want to reset the first order number to a different value - to pick up where your old e-commerce system left off, for example, or simply because single-digit order numbers give the wrong (or right?) impression to your customers.

Ubercart stores order numbers in the database.
For Ubercart version 2.x on Drupal 6:

The order ID is stored in an autoincrement database field.
In order to change it, run the following SQL command "alter table uc_orders auto_increment = 999;"
Where 999 is one less then the number you desire for the next order (1000 in this example).
Your new starting order number must be higher than any existing order numbers!

For Ubercart 1.x on Drupal 5:

If you're using MySQL as your database, it's in a table called sequences in a row named uc_orders_order_id. You can use a tool like phpMyAdmin to alter the value stored in this row, or you can execute the following SQL. In this example, we will set the new starting order number to "1234":

UPDATE sequences SET id = 1233 WHERE name = 'uc_orders_order_id';

Note that the next order placed will be one greater than the number stored in this table, so if we want to start at "1234" we set the column to be "1233".

Your new starting order number must be higher than any existing order numbers! If there is no row for this variable, it is recommended you create a test order so the order ID row gets set, then adjust it as described above.

If you're using PostgreSQL, the procedure is different. The order number is stored in a sequence called uc_orders_order_id_seq. To change the sequence value you need to use the following statement. Again, using "1234" as our desired starting order number:

SELECT setval('uc_orders_order_id_seq', 1233);

This will update the uc_orders_order_id_seq sequence, and the numbering of new orders will start with the number following the one given as the second parameter.

In both cases, be sure to take your site off-line before you modify the database in this manner - you don't want to interfere with an order in progress! Furthermore, you should be aware that a maximum order number of 8388607 exists because of the data type used for the database column. Be sure to leave plenty of room for the orders to start rolling in.

dylan's picture
Offline
Joined: 11/20/2008
Juice: 2
Re: How do I set/reset the starting order number for my store?

In drupal 6 the sequences table was eliminated, in favor of autoincrement database tables.

So the code for the D6 version of ubercart (using MySQL) is
alter table uc_orders auto_increment = 6858;

svihel's picture
Offline
Joined: 05/29/2008
Juice: 140
Hello, I tried this, but if

Hello,
I tried this, but if I use number which contains more than 7 digits and then try to make an order it will give me this error:

    * user warning: Duplicate entry '8388607' for key 1 query: INSERT INTO uc_orders (order_id, uid, order_status, order_total, primary_email, delivery_first_name, delivery_last_name, delivery_phone, delivery_company, delivery_street1, delivery_street2, delivery_city, delivery_zone, delivery_postal_code, delivery_country, billing_first_name, billing_last_name, billing_phone, billing_company, billing_street1, billing_street2, billing_city, billing_zone, billing_postal_code, billing_country, payment_method, data, created, modified) VALUES (20092629, 2, 'in_checkout', 0, 'svihel@gmail.com', '', '', '', '', '', '', '', 0, '', 0, '', '', '', '', '', '', '', 0, 0, 0, '', '', 1234373160, 1234373160) in C:\wamp\www\testovaci-shop\includes\database.mysql.inc on line 174.
    * user warning: Duplicate entry '16777215-flatrate_1' for key 1 query: INSERT INTO uc_order_quotes (oid, method, accessorials, rate, quote_form) VALUES (20092629, 'flatrate_1', '0', 0, '') in C:\wamp\www\testovaci-shop\includes\database.mysql.inc on line 174.

I looked at the database and the value uc_orders_order_id should contain 10 digits, I even later tried to heighten this number but it didn't help. BTW reason why I want such a big number is because I need this to my accounting to have order number like year_month_ordernumber, so for example this - 2009020054.

I'm using Ubercart 5.x-1.7

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3369
Re: Hello, I tried this, but if

As it says in the FAQ: Furthermore, you should be aware that a maximum order number of 8388607 exists because of the data type used for the database column.

If you wish to propose changing this limit you need to bring up a discussion in the main forums, not here in the FAQ.

<tr>.
svihel's picture
Offline
Joined: 05/29/2008
Juice: 140
Re: Re: Hello, I tried this, but if

Oh, sorry I must overlooked that. Nevertheless I at first thought that simple changing that limit in database layer would be enough.
Anyway thanks for reply.

troca's picture
Offline
Joined: 07/14/2009
Juice: 17
Dont understand In drupal 6

Dont understand

In drupal 6 the sequences table was eliminated, in favor of autoincrement database tables.

So the code for the D6 version of ubercart (using MySQL) is
alter table uc_orders auto_increment = 6858;

thanks for info finaly figured out how to do it Smiling

secondglance's picture
Offline
Joined: 11/10/2009
Juice: 43
Re: Re: How do I set/reset the starting order number for my stor

wooooohoooooooo.....it works.

JAScarb's picture
Offline
Joined: 03/08/2010
Juice: 31
Not sequences

I don't appear to have a sequences table, Ubercart 6.x-2.2

Ah .. I didn't think there were any comments to this. OK, solved above Smiling

James Peck's picture
Offline
Joined: 10/20/2010
Juice: 51
Non-developer version

Hi There.

I'm probably being a bit thick - what do I do with the code - "alter table uc_orders auto_increment = 6858;" - i.e. where do I put it..?

I've tried putting it in various places - but I clearly have no idea what I'm doing!

Please help

Best Wishes

James Peck's picture
Offline
Joined: 10/20/2010
Juice: 51
Non-developers...

Finally answered my own question - you don't "put" it anywhere...

I went to phpMyAdmin (via my hosts control panel)

There is a little box in the top right corner with SQL written on it. Clicking this opened a "run sql queries" dialog box.

Paste the code " alter table uc_orders auto_increment = 6858; " and press Go (I used 16858 instead of 6858)

It works - brilliant - an idiot could do it - one just did...

jburnard's picture
Offline
Joined: 03/01/2009
Juice: 147
Thank you James Peck! I

Thank you James Peck!

I needed the step by step for children version of this and I followed what you did and it worked perfectly for me as well. Thanks so much for coming back here even after you solved it and helping out.

cmmeier's picture
Offline
Joined: 02/22/2011
Juice: 5
Not changing the order id

I have tried running alter table uc_orders auto_increment = 999; but still my order ids are in the single digits. I am just at the beginning of our store use and only have 10 or eleven orders. I don't know a lot about MySQL but I am learning. Am I missing something? The site is hosted on a shared server, could there be some sort of permissions issue preventing this change? When I run it, I don't get any errors.
mysql> ALTER TABLE uc_orders AUTO_INCREMENT=999;
Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0
Any help or suggestions would be appreciated.

Thanks!

Kalorlo's picture
Offline
Joined: 11/19/2010
Juice: 75
Re: Not changing the order id

My table's actually called dr_uc_orders, not uc_orders. If you're using phpMyAdmin it will show you a handy list of tables, so if this isn't working have a look to see what your table is called and use that name in the query.

seagle's picture
Offline
Joined: 09/16/2011
Juice: 22
Yes

"So the code for the D6 version of ubercart (using MySQL) is
alter table uc_orders auto_increment = 6858;"

same in D7, very helpful, thanks!