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. 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.

Joined: 11/20/2008
Juice: 2

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;

Joined: 05/29/2008
Juice: 132

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
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3220

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>.
Joined: 05/29/2008
Juice: 132

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.

Joined: 07/14/2009
Juice: 17

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