Content Migration from Drupal-7 to Drupal-8

February 9, 2017
admin

Contributor: Khalid Mahmod, Nascenia

We can easily and automatically migrate data from our existing D6 or D7 site to D8 site. Drush (Drupal Shell) is an excellent tool to migrate data from Drupal 7 to Drupal 8. The migration process is described below step by step:

Step-1: Create a Drupal 8  site

There are two ways to do this. You can download the files from Drupal.org and extract them into your local development manually. My preferred method is via Drush. If you’re not using Drush, I highly suggest it. Instructions for getting up and running with Drush can be found here. Make sure you’re using at least version 7 as Drupal 8 doesn’t work with earlier versions of Drush.

Navigate to wherever you store your local development sites and run the following:

drush dl drupal-8 --select

Install the Drupal 8 site.

Step-2: Install Necessary Modules via Drush

Install the following modules via drush to migrate data from D7 to D8:

drush en migrate_tools -y

Migrate Tools will add Drush Migrate commands, like drush migrate-status (ms) and drush migrate-import (mi). If you enable this module and try drush migrate-status without doing anything with the Migrate Upgrade module you won’t see any migrations available to run. That’s because the individual migrations are created dynamically based on the source database you set up. Since Migrate has no idea yet what source to use, no migrations have been created.

To solve that we need the Migrate Upgrade module. Migrate Upgrade comes with a Drush command:

drush en migrate_upgrade -y

This module does two things:

  1. It will generate migrations for your site, based on migrate_drupal’s migration templates and your configured source site. For instance, the d6_book migration is only created if the Book module is enabled on both your Drupal 6 and Drupal 8 sites.
  2. It executes every created migration, in dependency order (because migrations can depend on other migrations — for instance, migrating nodes depends first on migrating users, so Migrate will ensure that the user migration runs before the node migration).
Step-3: Database configuration for Migration

After enabling the required modules, add an additional database definition to your settings.php for your Drupal 8 site:

// Database entry for `drush migrate-upgrade --configure-only`
$databases['upgrade']['default'] = array (
 'database' => 'dbname',
 'username' => 'dbuser',
 'password' => 'dbpass',
 'prefix' => '',
 'host' => 'localhost',
 'port' => '3306',
 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
 'driver' => 'mysql',
);
// Database entry for `drush migrate-import --all`
$databases['migrate']['default'] = array (
 'database' => 'dbname',
 'username' => 'dbuser',
 'password' => 'dbpass',
 'prefix' => '',
 'host' => 'localhost',
 'port' => '3306',
 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
 'driver' => 'mysql',
);
Step-4: Start Data Migration Process

Now we are going to run migrate-upgrade. However, for more control, you will probably want to pass the –configure-only option to migrate-upgrade, so it will only perform the first step of creating the migrations:

drush migrate-upgrade --legacy-db-url=mysql://root@localhost/telenorhealth
--legacy-root=/Applications/XAMPP/htdocs/evergreen --configure-only

After running migrate-upgrade with the –configure-only parameter, you run migrate-status to see the list of possible migrations:

drush migrate-status

Then you can review and selectively execute these migrations. To perform the migrations individually run:

drush migrate-import {migration name}

To perform all the migrations in the list, run:

drush migrate-import --all

Your D7 data should be migrated successfully to D8 site after running above command.

Step-5: Fix Post Migration Issues

Here’s a quick look at some of the issues we ran into with Drupal 8 migration tools:

  • Menu inconsistencies (because back in the day the “main menu” was called “primary links”)
  • Lost role assignments despite user migration
  • Duplicated taxonomy vocabularies
  • Some incomplete or duplicated content types and content field definitions
  • Some data that didn’t carry over, such as content statistics
  • Data issues on content language assignment (‘und’ vs ‘English’)
  • Taxonomy mappings with articles are lost.

So, from the admin panel, we fixed the taxonomy mapping. Visit Home >> Administration >> Structure >> Content types >> Article >> Manage fields

Click “Edit” for any fields which should be referenced to taxonomy terms and select the appropriate Taxonomy Vocabulary. For Example – Article field “Category” Should be referenced with “Category” Vocabulary.

To Fix the “langcode” issue happened after data migration, I enabled the “Language” Module and added “Bengali” language as all of D7 contents’ langcode were “bn”.

Queries ran in Drupal 8 DB:

UPDATE node_body
SET langcode='bn'

UPDATE node__field_category
SET langcode='bn'

UPDATE node__field_has_video
SET langcode='bn'

UPDATE node__field_has_video_image
SET langcode='bn'

UPDATE node__field_health_topics
SET langcode='bn'

UPDATE node__field_image
SET langcode='bn'

UPDATE node__field_internal_tags
SET langcode='bn'

UPDATE node__field_is_feature
SET langcode='bn'

UPDATE node__field_is_topic_feature
SET langcode='bn'

UPDATE node__field_personalization
SET langcode='bn'

UPDATE node__field_teaser
SET langcode='bn'

UPDATE node__field_thumbnil
SET langcode='bn'

In this way, I migrated all data of D7 to D8 successfully.

1 Comment. Leave new

I feel the article gave me some valuable information on content migration from drupal 7 to 8. The way you featured your content is amazing and more informative as well.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.