In practice, the initial migration takes place earlier than switching the site over to the new platform, so Magento 2 introduced the concept of delta migration. Delta migration supposed to transfer all the data since the last run in the fraction of the time required to run the initial migration.

This method is only theoretical because, during development, it’s very rare when we don’t have to change product attributes, introduce new features or place test orders. If the data changed between the two migration runs, the delta migration will most definitely fail.

So instead of running a delta migration, sometimes it’s better to run the migration for customers and orders only. This will allow the developers to place test orders and change product structure and add new product attributes without affecting the migration process. To do so, the data migration should be configured to not touch anything else other than customer and order data. Customer and order data should be truncated on the target database before we run the data migration tool. The data migration tool is creating tables in the Magento 1 database as well so we will have to ignore these and run a dry migration like the first time.

It sounds complicated, but trust me, it’s a whole lot easier than making the delta migration work on a changed data structure. First, it’s required to ignore everything else other than orders and customers. This should go to the map.xml map > destination > document_rules XML path:

            <ignore>
                <document>catalog_category*</document>
            </ignore>
            <ignore>
                <document>catalog_compare*</document>
            </ignore>
            <ignore>
                <document>catalog_eav_attribute</document>
            </ignore>
            <ignore>
                <document>cataloginventory_stock*</document>
            </ignore>
            <ignore>
                <document>catalog_product_*</document>
            </ignore>
            <ignore>
                <document>core_*</document>
            </ignore>
            <ignore>
                <document>cms_*</document>
            </ignore>

To run the data migration, one should also prepare the database. Truncate orders and customers data on the Magento 2 database:

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `gift_message`;
TRUNCATE TABLE `quote`;
TRUNCATE TABLE `quote_address`;
TRUNCATE TABLE `quote_address_item`;
TRUNCATE TABLE `quote_id_mask`;
TRUNCATE TABLE `quote_item`;
TRUNCATE TABLE `quote_item_option`;
TRUNCATE TABLE `quote_payment`;
TRUNCATE TABLE `quote_shipping_rate`;
TRUNCATE TABLE `reporting_orders`;
TRUNCATE TABLE `sales_bestsellers_aggregated_daily`;
TRUNCATE TABLE `sales_bestsellers_aggregated_monthly`;
TRUNCATE TABLE `sales_bestsellers_aggregated_yearly`;
TRUNCATE TABLE `sales_creditmemo`;
TRUNCATE TABLE `sales_creditmemo_comment`;
TRUNCATE TABLE `sales_creditmemo_grid`;
TRUNCATE TABLE `sales_creditmemo_item`;
TRUNCATE TABLE `sales_invoice`;
TRUNCATE TABLE `sales_invoiced_aggregated`;
TRUNCATE TABLE `sales_invoiced_aggregated_order`;
TRUNCATE TABLE `sales_invoice_comment`;
TRUNCATE TABLE `sales_invoice_grid`;
TRUNCATE TABLE `sales_invoice_item`;
TRUNCATE TABLE `sales_order`;
TRUNCATE TABLE `sales_order_address`;
TRUNCATE TABLE `sales_order_aggregated_created`;
TRUNCATE TABLE `sales_order_aggregated_updated`;
TRUNCATE TABLE `sales_order_grid`;
TRUNCATE TABLE `sales_order_item`;
TRUNCATE TABLE `sales_order_payment`;
TRUNCATE TABLE `sales_order_status_history`;
TRUNCATE TABLE `sales_order_tax`;
TRUNCATE TABLE `sales_order_tax_item`;
TRUNCATE TABLE `sales_payment_transaction`;
TRUNCATE TABLE `sales_refunded_aggregated`;
TRUNCATE TABLE `sales_refunded_aggregated_order`;
TRUNCATE TABLE `sales_shipment`;
TRUNCATE TABLE `sales_shipment_comment`;
TRUNCATE TABLE `sales_shipment_grid`;
TRUNCATE TABLE `sales_shipment_item`;
TRUNCATE TABLE `sales_shipment_track`;
TRUNCATE TABLE `sales_shipping_aggregated`;
TRUNCATE TABLE `sales_shipping_aggregated_order`;
TRUNCATE TABLE `tax_order_aggregated_created`;
TRUNCATE TABLE `tax_order_aggregated_updated`;

TRUNCATE TABLE `customer_address_entity`;
TRUNCATE TABLE `customer_address_entity_datetime`;
TRUNCATE TABLE `customer_address_entity_decimal`;
TRUNCATE TABLE `customer_address_entity_int`;
TRUNCATE TABLE `customer_address_entity_text`;
TRUNCATE TABLE `customer_address_entity_varchar`;
TRUNCATE TABLE `customer_entity`;
TRUNCATE TABLE `customer_entity_datetime`;
TRUNCATE TABLE `customer_entity_decimal`;
TRUNCATE TABLE `customer_entity_int`;
TRUNCATE TABLE `customer_entity_text`;
TRUNCATE TABLE `customer_entity_varchar`;
TRUNCATE TABLE `customer_grid_flat`;
TRUNCATE TABLE `customer_log`;
TRUNCATE TABLE `customer_log`;
TRUNCATE TABLE `customer_visitor`;
TRUNCATE TABLE `persistent_session`;
TRUNCATE TABLE `wishlist`;
TRUNCATE TABLE `wishlist_item`;
TRUNCATE TABLE `wishlist_item_option`;
SET FOREIGN_KEY_CHECKS = 1;

Then run the migration using the -r switch:

bin/magento migrate:data dev/migration/config.xml -r

This is how it works. Hopefully, it will be useful for someone. This is a process I developed while migrating > 5 Magento stores to Magento 2 and I’m keen to hear about others. If you think your process is better, please comment below.

Updated:

Comments