Migrating data into a Drupal 7 site from an external source can be time-consuming, especially if you're unfamiliar with migration processes and data sources. Fortunately, the Migrate module simplifies this task by providing a powerful and easy-to-use interface.
This guide walks you through an example of migrating data from a database table to create nodes of a content type in Drupal. For this demonstration, we will use a content type called Activities, which includes a title, body, and image field.
Enable the Necessary Modules
Start by enabling the Migrate module and its user interface extension, Migrate UI, using Drush:
Create a Custom Migration Module
Create a custom module named migrate_activities
. In the module’s .info
file, declare the Migrate module as a dependency:
migrate_activities.info
migrate_activities.module
(can remain empty)migrate_activities.migrate.inc
activities.inc
(contains the migration class definition)
Use the hook_migrate_api()
in the migrate_activities.migrate.inc
file to register the migration group:
This hook registers the migration group (activities_group
) and the associated class (MigrateActivities
).
Create the activities.inc
file and define the MigrateActivities
class. Ensure the class extends the Migration
class:
Add a connection to the database from which data will be migrated in the settings.php
file:
Register the Migration
Navigate to the migration configuration page:
Click Register statically defined classes to register the migration.
Start the Migration
On the dashboard (admin/content/migrate
), locate your migration group. Click the Import option to start the migration process.
The Migrate module in Drupal 7 is a robust tool for transferring data from various sources into your site. With its ability to handle complex migrations, this module is indispensable for projects involving significant content migration. By automating the process, you save hours of manual work and ensure consistency in the data migration.
For more details, refer to the official Migrate documentation on Drupal.org.