Transferring your Magento 1 database to Magento 2

Moving your Magento 1 to Magento 2 may be one of the most challenging things out there. Luckily, Magento supported us with a database migration option.

The Magento 2 Data Migration Tool is here to help you convert your products, customers, order/sales data, store configuration, promotions/sales rules, and more to move to a clean Magento 2 setup.

Custom code, Extensions, and Themes are out of the current scope of the Data Migration Tool.

The currently supported migrations are the Community Edition (CE) versions 1.6.x, 1.7.x, 1.8.x, and 1.9.x and Enterprise Edition (EE) versions 1.11.x, 1.12.x, 1.14.x, and 1.14.x.

Tip

Check with your third-party extension developer for a Data Migration Tool to move the database code base to Magento 2.

Getting ready

Before we can start migrating our system, we need to check the following:

  • Have a clean Magento 2 system running as we set up in Chapter 1, Installing Magento 2 on Apache and NGINX.
  • Disable your cron jobs.
  • Always back up your databases and old and new Magento versions.
  • Check whether there is a network connection from the current Magento 1 to Magento 2 server. Check the firewall for database access if needed (port 3306).
  • Only use the exact version number, so that the data-migration-tool 2.0.0 corresponds with Magento 2.0.0.

Tip

You may copy your current production database to the new Magento 2 server and run it there.

A migration of Magento 1 to Magento 2 has the following five phases that are important to follow in the correct order:

  1. Settings: Migration of the settings is step 1. This will transfer all information from the stores, website, and system configuration.

    The command is php bin/magento migrate:settings.

  2. Data: Migration of the data is step 2. This will transfer all categories, products, customers, orders, wishlists, ratings, and so on

    The command is php bin/magento migrate:data.

  3. Delta: Migration of the delta is step 3. This is an important step and is used to transfer Magento 1 data to Magento 2 where new updates occur. It will update the most recent data of customers, orders, or other customer-related data. It is common to use this command before going live.

    The command is php bin/magento migrate:delta.

  4. Media: Migration of the media files is easy; just copy all files from /media to /pub/media.
  5. Custom modules/themes: Migration of your modules or themes is out of the scope of the migration tool. Contact your solutions provider to check whether they have a new version available. This also applies to any custom-made themes of theme packages bought online.

How to do it...

For the purpose of this recipe, let's assume that we need to manage a Magento 1 to Magento 2 migration setup. The following steps will guide you through this:

  1. First, we need to run the following command to add data-migration-tool to your current Composer setup:
    composer config repositories.data-migration-tool git https://github.com/magento/data-migration-tool-ce
    composer require magento/data-migration-tool:dev-master
    

    Wait while all dependencies are updated.

  2. Now check whether the migration tools are available in the bin/magento shell tool:

    Commands

    Description

    migrate

     

    migrate:data

    Main migration of data

    migrate:delta

    Migration of the data that is added to Magento after the main migration

    migrate:settings

    Migration of the system configuration

  3. For this recipe, we will be using a Magento 1 database installation on our DigitalOcean Droplet. You may pick any of your production or Magento 1 sample data SQL dumps. We will be using a Magento 1.9.2.2 sample data SQL dump. Our database is called magento1.
  4. Now, we need to map the database configuration files from the Magento 1 database to the Magento 2 database. Always make sure that you are using a clean database; otherwise, you can run the following command:
    php bin/magento setup:uninstall
    

    Go to /var/www/html/vendor/magento/data-migration-tool/etc/ce-to-ce and pick the correct database version mentioned in the directory. If correct, you will see two files called config.xml.dist and map.xml.dist.

  5. Copy config.xml.dist to config.xml using the cp command:
    cp config.xml.dist config.xml
    
  6. Open your config.xml and look for the <source> tag (line 94). Change it accurately with the database username and password:
    <source>
      <database host="localhost" name="magento1" user="root" password="mypassword"/>
    </source>
    <destination>
      <database host="localhost" name="magento2" user="root" password="mypassword"/>
    </destination>
    <options>
      <source_prefix>myprefix-from-magento1</source_prefix>
      <crypt_key>mycrypt-key-from-magento1</crypt_key>
    </options>

    If you are using a custom prefix in your database or you wish to use your encryption key on your Magento 2 setup, you can add this to the <options> section, as shown in the previous code.

  7. Now we can start step 1 of the settings migration using the following command:
    php bin/magento migrate:settings /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    As you can see, here we are using the 1.9.2.2 version. Depending on your version, you may change this before running the command.

    The output result looks like this:

    [2015-12-02 20:28:56][INFO][mode: settings][stage: integrity check][step: Settings Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:56][INFO][mode: settings][stage: integrity check][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:56][INFO][mode: settings][stage: data migration][step: Settings Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: data migration][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: volume check][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: volume check][step: Stores Step]: Migration completed
    
  8. You can check your Magento 2 system configuration backend if all updated settings are available. If so, you can continue.
  9. If step 1 is correct, we continue to migrate our data to Magento 2 using the following command:
    php bin/magento migrate:data /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    The output result looks like this:

    How to do it...
  10. You can check your Magento 2 catalogs, products, orders, and customers if they are all updated. If so, you can continue.
  11. Before you continue, make sure to reindex and flush your caches at once:
    php bin/magento indexer:reindex
    php bin/magento cache:clean
    php bin/magento cache:flush
    
  12. Now check the frontend and backend whether your data is available in Magento 2. If not, check the migration.log file located in /var.
  13. In this recipe, we used a default Magento 1.9.2.2 setup. After the settings and data migration, we created a sales order in Magento 1. Now, using the delta option, we push the data to Magento 2 using the following command:
    php bin/magento migrate:delta /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    The output result looks like this:

    How to do it...
  14. Now check your sales and customer data. Congratulations, you successfully migrated your database from Magento 1 to Magento 2.

How it works…

Let's recap and find out what we did throughout this recipe. In steps 1 through 14, you learned how to use the Magento 2 migration tool.

In step 1, we used Composer to add an additional repository for data migration. After installing all of the packages, they are available in the bin/magento tool. In this setup example, we used a clean Magento 1.9.x database.

In step 4, we made sure to run on a clean Magento 2 setup. Depending on your setup, go to vendor/magento/data-migration-tool/etc and select the correct version. Magento 2 supports the migration option for CE and EE. Once we configured the config.xml file with the Magento 1 database information in step 6, we were ready to go.

In step 7, we used the bin/magento migration setting to start the whole process. We started with the setting parameter and continued with the data and delta parameters in steps 7 through 13. We must not forget the reindexing and updating of our caches before using them. The delta parameter option can be run multiple times as it only updates the latest information, which is helpful before going live and switching to production.

There's more…

As every Magento setup is unique, migrating from Magento 1 to Magento 2 can be hard sometimes. In some situations, you may need to change your tables in the mapping configuration located in vendor/magento/data-migration-tool/etc/ce-to-ce/<version>map.xml.dist.

Resetting your setting, data, and delta migration is easy using the [-r|--reset] parameter in your command. This allows you to rerun all migration scripts from the beginning.

Always check for the currently supported versions on the Magento GitHub Data Migration Tool page at the following link:

https://github.com/magento/data-migration-tool-ce

Tip

There is also an alternative Data Migration Tool available by UberTheme at https://github.com/ubertheme/magento2_data_migration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.77.158