Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active May 30, 2019 02:48
Show Gist options
  • Save peterjaap/9952588 to your computer and use it in GitHub Desktop.
Save peterjaap/9952588 to your computer and use it in GitHub Desktop.
Remove orders, invoices, shipments, creditmemos, customers and quotes from Magento
# Empty relevant tables
DELETE FROM sales_flat_creditmemo;
DELETE FROM sales_flat_invoice;
DELETE FROM sales_flat_order;
DELETE FROM sales_flat_quote;
DELETE FROM sales_flat_shipment;
DELETE FROM customer_entity;
# Reset increment_ids
# Beware of store_ids when using multiple stores
# Change 'increment_last_id' and 'increment_prefix' to for example '200000001' to start a new series
# Always set 'increment_prefix' to the first number of your 'increment_last_id'
# You can also prefix some string, such as 'ORD'. Set 'increment_prefix' to 'ORD1' and 'increment_last_id' to 'ORD100000001'
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = '100000001' WHERE store_id = 1 AND entity_type_id = 1; # customers
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = '100000001' WHERE store_id = 1 AND entity_type_id = 5; # orders
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = '100000001' WHERE store_id = 1 AND entity_type_id = 6; # invoices
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = '100000001' WHERE store_id = 1 AND entity_type_id = 7; # creditmemos
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = '100000001' WHERE store_id = 1 AND entity_type_id = 8; # shipments
# Update increment lengths (for example, change these from 8 to 6 if you want 1000001 instead of 100000001)
UPDATE eav_entity_type SET increment_pad_length = 8 WHERE entity_type_id = 1; # customers
UPDATE eav_entity_type SET increment_pad_length = 8 WHERE entity_type_id = 5; # orders
UPDATE eav_entity_type SET increment_pad_length = 8 WHERE entity_type_id = 6; # invoices
UPDATE eav_entity_type SET increment_pad_length = 8 WHERE entity_type_id = 7; # creditmemos
UPDATE eav_entity_type SET increment_pad_length = 8 WHERE entity_type_id = 8; # shipments
# Reset auto_increments
ALTER TABLE sales_flat_invoice AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_invoice_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_invoice_grid AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_invoice_comment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_creditmemo AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_creditmemo_comment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_creditmemo_grid AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_creditmemo_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order_address AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order_grid AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order_payment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_order_status_history AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_address AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_address_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_item_option AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_payment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_quote_shipping_rate AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_shipment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_shipment_item AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_shipment_grid AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_shipment_comment AUTO_INCREMENT = 1;
ALTER TABLE sales_flat_shipment_track AUTO_INCREMENT = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment