I am willing to get product SKU value to auto-increment in Magento 2. For example the last product created sku was 100001 then the next product would be 100002 and so on.

2 Answers 2


Till now Magento does not have such functionality. Though Magento provides the feature to set the mask for autogenerating SKU field.

To do so, go to

Stores > Configuration > Catalog > Product Fields Auto-Generation

and set value of Mask for SKU field.

If you still want to auto-generate SKU field like 100001, 100002 etc., then you need to create a custom module which will observe the event of product edit form load. On this event, check whether it is an old product being edited or a new product is being created.

If a new product is being created, then you would need to get last SKU from the table and fill the value of SKU with (last SKU + 1) value.

Note: Before doing above exercise, you would need to make two changes for SKU attribute:

  • Change SKU data type to integer
  • Make the SKU field read-only, so that admin cannot change the generated value

Please check and let me know if you have any question.


I've found this module on github which seems to be exactly what you're looking for


From the Link: magento2 auto generate sku for new product based on custom confgiuration. Auto SKU Generator Addon provides the functionality of generating the SKU automatically

Examples 1 : Prefix -> D, Start From -> 1, SKU Length -> 5 D00001, D0002, D0003 ,........

3 : Prefix -> SKU, Start From -> 1, SKU Length -> 7 SKU0001, SKU0002, SKU0003, SKU0004 ,....................

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Jarnail S
    Commented Jan 30, 2018 at 11:41
  • 1
    I've added more info.
    – paalsoberg
    Commented Jan 30, 2018 at 12:50

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.