Using the Migrate Source CSV plugin

Last updated on
3 March 2017

The Migrate Source CSV module provides a source plugin for utilizing .csv files as migration sources.


How to import a simple CSV-file with Migrate Source CSV plugin

This very basic example will show you how to import Title and Body into the Article content type from a CSV-file.

  1. Download Migrate Source CSV and enable it.
  2. Download Migrate Plus and enable it
  3. Download Migrate Tools and enable it.
  4. Ensure you're using the latest version of Drush.
  5. Create a sample CSV-file called acme_articles.csv with the following content:
    1,title 1,some body text 1 
    2,title 2,some body text 2 
    3,title 3,some body text 3
  6. Navigate to Administration > Configuration > Development > Synchronize (admin/config/development/configuration/single/import), select Migration under Configuration type and enter this CSV-import configuration into the Paste your configuration here window (note the absolute path to the .csv file) , and hit import:
    id: basics
    label: Import articles
      - ACME import
      plugin: csv
      path: '/path/to/file/acme_articles.csv'
      header_row_count: 1
        - Id2
      title: title
      body: body
        plugin: default_value
        default_value: article
      plugin: entity:node
  7. Go to your terminal and execute the command drush migrate-import basics to import the three example articles. If there is an error in your yml-configuration, and you try to resubmit it, you might have to change the id from basics to something else for it to get accepted (this is because by default, Drupal 8 doesn't allow existing configurations to be overwritten; you can however export the migration configuration (contains a uuid) and reimport the changed configuration (with the exported uuid) with the same id).

How to override the path to the CSV-file

using drupal console and a migration named basics:

drupal config:override migrate_plus.migration.basics source.path /path-to.csv

View or edit existing migration configuration

drupal config:edit migrate_plus.migration.basics

You will need to run drush cr to rebuild the cache before importing the file again. You'll need to rollback first too for any changes to "process" section (e.g. changes to default values) to be applied.