
Magento 2 builds every order number from three things: a profile row in sales_sequence_profile that holds the prefix, suffix, start value, and step, a per store counter table such as sequence_order_1, and a fixed pattern that pads the number to nine digits. To change the prefix, update the profile. To change the next number, change the counter table’s AUTO_INCREMENT.
There is no admin screen for any of this, which is why the question comes up on almost every migration and every new store view. The mechanism is small, though, and once you have read the three tables you can change numbering with confidence and avoid the two classic mistakes: creating duplicate order numbers, and editing start_value and expecting the next number to move.
increment_id is not entity_id
Every sales document has two identifiers.
entity_id |
increment_id |
|
|---|---|---|
| What it is | Auto increment primary key of sales_order |
The human facing number, for example 000000123 |
| Who sees it | Developers, the URL of the admin order page, REST paths such as /V1/orders/:id |
Customers, emails, PDFs, customer service, the ERP |
| Scope | One sequence for the whole table | One sequence per store view and per document type |
| Type | Integer | String, because it can carry a prefix and suffix |
| Can you customize it | No | Yes |
Integrations trip over this constantly. The REST route /V1/orders/123 wants the entity_id. To find an order by the number a customer quotes, search on increment_id with search criteria, as Adobe’s guide to searching with REST endpoints describes.
The three pieces behind a number
All of this lives in the Magento_SalesSequence module, whose source is in the Magento 2 repository on GitHub.
sales_sequence_meta
One row per document type per store view. It maps the pair to a counter table.
| Column | Meaning |
|---|---|
meta_id |
Primary key |
entity_type |
order, invoice, creditmemo, or shipment |
store_id |
The store view |
sequence_table |
The counter table, for example sequence_order_1 |
sales_sequence_profile
One active row per meta row. It holds the formatting rules.
| Column | Meaning |
|---|---|
profile_id |
Primary key |
meta_id |
The meta row this profile belongs to |
prefix |
Text placed before the number |
suffix |
Text placed after the number |
start_value |
The number the counter was created to start from |
step |
The multiplier applied to the counter |
max_value, warning_value |
Upper bounds stored with the profile |
is_active |
Whether this profile is in use |
The counter tables
sequence_order_1, sequence_invoice_1, sequence_creditmemo_1, sequence_shipment_1, and the same set again for every other store view. The builder names them with the pattern sequence_<entity_type>_<store_id>. Each has a single auto increment column, sequence_value.
To see how a store is configured:
SELECT m.entity_type, m.store_id, m.sequence_table,
p.prefix, p.suffix, p.start_value, p.step
FROM sales_sequence_meta m
JOIN sales_sequence_profile p ON p.meta_id = m.meta_id AND p.is_active = 1
ORDER BY m.store_id, m.entity_type;
How the number is calculated
The logic is three short methods in Magento\SalesSequence\Model\Sequence.
getNextValue()inserts an empty row into the counter table and reads back the new auto increment value.calculateCurrentValue()applies the profile:(counter - start_value) * step + start_value.getCurrentValue()formats the result withsprintfusing the pattern%s%'.09d%s: prefix, the number zero padded to nine digits, suffix.
With the defaults of start value 1 and step 1, the calculation returns the counter unchanged. Counter 123 with an empty prefix gives 000000123.
Three consequences follow directly from that code.
- The counter is the source of truth. The next number comes from the table’s AUTO_INCREMENT.
start_valueis only used when the counter table is first created. On an existing store with step 1, changingstart_valuehas no effect at all, because it is subtracted and then added back. - Step is a multiplier relative to start_value. With start 1 and step 5, counters 1, 2, 3 produce 1, 6, 11. If you later change
start_valueon a store with a step other than 1, the formula produces numbers that jump or go negative. Leave step at 1 unless you have a specific reason. - Numbers are strings. Sorting them as text works only because of the zero padding. Do not cast them to integers in integrations once a prefix is involved.
Why every store view has its own numbering
When a store view is created, Magento\SalesSequence\Observer\SequenceCreatorObserver builds a meta row, a profile, and a counter table for each document type, and it sets the profile’s prefix to the store ID. That is why orders from a second store view start with 2 and look like 2000000001, while the first store view’s orders look like 000000001.
This gives each store view an independent counter. The prefix keeps the numbers unique across the installation, and the database enforces it with a unique index on increment_id and store_id in sales_order. If you run several brands or regions from one install, as described in our guide to multi-website architecture on Magento and Hyva, decide the numbering scheme per store view before launch, because customers and finance teams will read meaning into the prefix.
Adding or changing a prefix
Update the active profile for the document type and store view. In SQL:
UPDATE sales_sequence_profile p
JOIN sales_sequence_meta m ON m.meta_id = p.meta_id
SET p.prefix = 'US-'
WHERE m.entity_type = 'order' AND m.store_id = 1 AND p.is_active = 1;
The next order on store view 1 becomes US-000000124. Existing orders are not renumbered.
Do not copy a meta_id out of a blog post. The IDs differ between installations, so always join through sales_sequence_meta on entity type and store.
For a change that should reach every environment, put it in a data patch instead of running SQL by hand. Load the meta row with Magento\SalesSequence\Model\ResourceModel\Meta::loadByEntityTypeAndStore('order', $storeId), call getActiveProfile(), set the prefix, and save the profile through its resource model. Our guide to writing idempotent Magento data patches covers the structure.
Things to check before choosing a prefix:
- Length. The
increment_idcolumn is a short string, and downstream systems are often stricter. Confirm the maximum order reference length your payment gateway, ERP, and carrier labels accept. - Characters. Stick to letters, digits, and a hyphen. Some gateways reject anything else in an order reference.
- All four document types. Invoices, shipments, and credit memos have their own profiles. If the order prefix changes and the invoice prefix does not, numbers stop lining up, which confuses customer service even though nothing is broken.
Changing the next order number
Move the counter:
ALTER TABLE sequence_order_1 AUTO_INCREMENT = 500000;
The next order on store view 1 will be 000500000 plus any prefix.
Rules that keep this safe:
- Only go up. If the new value is lower than a number already used with the same prefix on that store, Magento will try to insert a duplicate
increment_idand order placement will fail on the unique index. CheckSELECT MAX(increment_id) FROM sales_order WHERE store_id = 1first. - Do it per document type.
sequence_invoice_1,sequence_shipment_1, andsequence_creditmemo_1are separate counters. - Do it per store view. Each has its own tables.
- Do it in a quiet moment. An
ALTER TABLEwhile orders are being placed risks a lock wait at checkout.
The common use is migration. When you move from another platform or from Magento 1, set each counter above the highest legacy number so new orders continue the old series and no customer ever sees a number reused.
Changing the padding length
Nine digits comes from the DEFAULT_PATTERN constant, %s%'.09d%s. The pattern is a constructor argument of the Sequence class, so it can be replaced through di.xml without overriding the class:
<type name="Magento\SalesSequence\Model\Sequence">
<arguments>
<argument name="pattern" xsi:type="string">%s%'.06d%s</argument>
</arguments>
</type>
That gives six digit padding for every document type and store. Shortening it on a live store means new numbers have a different length from old ones, which breaks text sorting and any system that validates on length. Pick the format before launch if you can.
Why there are gaps in order numbers
Merchants regularly notice that order numbers skip. This is expected, for two reasons.
- The number is reserved before the order exists. During checkout Magento reserves an order ID on the quote, stored in
quote.reserved_order_id, so the payment gateway can be given a reference. If the payment fails or the customer abandons, that number has been consumed. - The counter never rolls back.
getNextValue()inserts a row into the counter table. An auto increment value that has been handed out is not reused, even when the surrounding transaction fails.
For most businesses that is fine. If you operate somewhere that requires gapless invoice numbering for tax purposes, know that Magento’s native sequences do not guarantee it. That requirement is usually met in the accounting system or with a dedicated numbering extension, and it is worth raising early with whoever runs your ERP integration. Our blueprint for integrating NetSuite with Magento and Adobe Commerce discusses how order references flow between the two systems.
Operational notes
- Counter tables grow by one row per document. They are narrow and cheap, and Magento only needs the AUTO_INCREMENT value, but on very high volume stores they are worth knowing about when you review table sizes.
- Staging copies. A staging database restored from production continues production’s numbering. If staging sends orders to a sandbox ERP, give staging its own prefix so test orders are obvious. Our article on sanitized production database copies for Magento staging covers the rest of that refresh process.
- New store views. Adding one creates new profiles with the store ID as prefix. If your scheme uses custom prefixes, add the profile update to your store creation checklist.
- Extensions. Several marketplace modules add an admin form for prefix, suffix, padding, and date based formats. They are a reasonable choice when non developers need to manage numbering. Underneath, they work with the same tables or replace the sequence class.
Does Hyva change order numbering?
No. Numbers are generated in the sales module when the order is placed, and the storefront only displays them. A Hyva storefront shows the same increment_id on the success page, in the account area, and in emails. If you change the format, check those templates and any tracking snippets that read the order number, which is a normal part of release testing for teams using our Hyva development services.
Numbering on other platforms
How much control you get varies. Shopify lets merchants set an order ID prefix and suffix in settings while the underlying number increments on its own. BigCommerce assigns sequential order IDs. Shopware has configurable number ranges per document type and sales channel in its admin. On a migration into Magento, the practical step is the same in each case: find the highest existing number and start the Magento counters above it.
Where Bemeir fits
Bemeir is a Brooklyn agency that builds, migrates, and supports Magento and Adobe Commerce stores. Getting order numbering right before go live is a small but real part of the migration work in our Magento development services. Read more about Bemeir or see our technology partners.
FAQ
How do I change the order number prefix in Magento 2?
Update the prefix column of the active row in sales_sequence_profile for the order entity type and the store view, found by joining to sales_sequence_meta. New orders use the prefix immediately. Existing orders keep their numbers. Repeat for invoice, shipment, and credit memo if you want them to match.
How do I set the next order number in Magento 2?
Run ALTER TABLE sequence_order_<store_id> AUTO_INCREMENT = <number>. The value must be higher than any number already used on that store view with the same prefix, or order placement will fail on the unique index.
Why does changing start_value not change my next order number?
start_value is only used when the counter table is created. After that the next number comes from the counter table’s AUTO_INCREMENT, and with a step of 1 the start value cancels out of the calculation. Change the AUTO_INCREMENT instead.
Why are there gaps in my Magento order numbers?
A number is reserved on the quote before payment, and the counter never reuses a value. Failed payments and abandoned checkouts therefore consume numbers. This is normal behavior and does not indicate lost orders.
Can each store view have its own order number format?
Yes for prefix, suffix, and counter, because each store view has its own profile and counter tables for each document type. The padding pattern is set once for the whole installation.





