|
| 1 | +--- |
| 2 | +group: configuration-guide |
| 3 | +title: Change increment ID for a database entity on particular store |
| 4 | +functional_areas: |
| 5 | + - Configuration |
| 6 | + - System |
| 7 | + - Setup |
| 8 | +--- |
| 9 | + |
| 10 | +This article discusses how to change the increment ID for a Magento database (DB) entity (order, invoice, credit memo, etc.) on a particular Magento store using the `ALTER TABLE` SQL statement. |
| 11 | + |
| 12 | +## Affected versions |
| 13 | + |
| 14 | +- {{site.data.var.ee}} (on premise): 2.x.x |
| 15 | +- {{site.data.var.ece}}: 2.x.x |
| 16 | +- MySQL: [any supported version][] |
| 17 | + |
| 18 | +## When would you need to change increment ID |
| 19 | + |
| 20 | +You might need to change the increment ID for new DB entities in these cases: |
| 21 | + |
| 22 | +- After a hard backup restore on a Live site |
| 23 | +- Some order records have been lost, but their IDs are already being used by payment gateways (like PayPal) for your current Merchant account. Such being the case, the payment gateways stop processing new orders that have the same IDs, returning the "Duplicate invoice id" error |
| 24 | + |
| 25 | +{: .bs-callout-info} |
| 26 | +You may also fix the payment gateway issue for PayPal by allowing multiple payments per invoice ID in PayPal's Payment Receiving Preferences. See [PayPal gateway rejected request - duplicate invoice issue][] in the _Knowledge Base_. |
| 27 | + |
| 28 | +## Prerequisite steps |
| 29 | + |
| 30 | +1. Find stores and entities for which the new increment ID should be changed. |
| 31 | +1. Connect to your MySQL DB. |
| 32 | + For {{site.data.var.ece}}, at first, you need to connect using SSH to your environment. |
| 33 | +1. Check the current `auto_increment` value for the entity sequence table using the following query: |
| 34 | + |
| 35 | + ```sql |
| 36 | + SHOW TABLE STATUS FROM `{database_name}` WHERE `name` LIKE 'sequence_{entity_type}_{store_id}'; |
| 37 | + ``` |
| 38 | + |
| 39 | +If you are checking an auto increment for an order on the store with ID=1, the table name would be 'sequence_order_1'. |
| 40 | + |
| 41 | +If the value of the `auto_increment` column is '1234', the next order placed at the store with `ID=1` will have the ID '#100001234'. |
| 42 | + |
| 43 | +## Update entity to change increment ID |
| 44 | + |
| 45 | +Update the entity using the following query: |
| 46 | + |
| 47 | +```sql |
| 48 | +ALTER TABLE sequence_{entity_type}_{store_id} AUTO_INCREMENT = {new_increment_value}; |
| 49 | +``` |
| 50 | + |
| 51 | +{: .bs-callout-info} |
| 52 | +Important: The new increment value must be greater than the current one. |
| 53 | + |
| 54 | +After executing the following query: |
| 55 | + |
| 56 | +```sql |
| 57 | +ALTER TABLE sequence_order_1 AUTO_INCREMENT = 2000; |
| 58 | +``` |
| 59 | + |
| 60 | +The next order placed at the store with `ID=1` will have the ID '#100002000'. |
| 61 | + |
| 62 | +## Additional recommended steps on cloud production environments |
| 63 | + |
| 64 | +Before executing the `ALTER TABLE` query on a production environment of {{site.data.var.ece}}, we strongly recommend performing these steps: |
| 65 | + |
| 66 | +- Test the entire procedure of changing the increment ID on your staging environment |
| 67 | +- [Create a DB backup][] to restore your Production DB in case of failure |
| 68 | + |
| 69 | +## Related documentation |
| 70 | + |
| 71 | +- [Set up a remote MySQL database connection][] |
| 72 | +- [Create database dump on Cloud][] |
| 73 | +- [SSH to your environment][] |
| 74 | + |
| 75 | +<!-- Link Definitions --> |
| 76 | +[PayPal gateway rejected request - duplicate invoice issue]: https://support.magento.com/hc/en-us/articles/115002457473 |
| 77 | +[Set up a remote MySQL database connection]: {{ page.baseurl }}/install-gde/prereq/mysql_remote.html |
| 78 | +[Create a DB backup]: https://support.magento.com/hc/en-us/articles/360003254334 |
| 79 | +[Create database dump on Cloud]: https://support.magento.com/hc/en-us/articles/360003254334 |
| 80 | +[SSH to your environment]: {{ page.baseurl }}/cloud/env/environments-ssh.html#ssh |
| 81 | +[any supported version]: {{ page.baseurl }}/install-gde/prereq/mysql.html |
0 commit comments