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.
Setting Up the Migrate Module
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 namedmigrate_activities
. In the module’s.info
file, declare the Migrate module as a dependency:- Add Necessary Files
Your module will consist of four files:migrate_activities.info
migrate_activities.module
(can remain empty)migrate_activities.migrate.inc
activities.inc
(contains the migration class definition)
Defining the Migration Group
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
).
Defining the Migration Class
Create the activities.inc
file and define the MigrateActivities
class. Ensure the class extends the Migration
class:
Configuring the Database Connection
Add a connection to the database from which data will be migrated in the settings.php
file:
Running the Migration
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.- Verify the Results
Once the migration is complete, new nodes will be created for the Activities content type. You can create a view to display the migrated content for verification.
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.