I'm trying to import the users from CSV file, but the import fails with the following error:

Migration failed with source plugin exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'map.sourceid4' in 'where clause', in includes/database/database.inc:2171

Migrate class is:


 * @file
 * Class for migrating users from a CSV file.

 * Class FooMigrateUsers.
class FooMigrateUsers extends Migration {

   * Constructor.
   * @inheritdoc
  public function __construct($arguments) {
    $this->description = t('Foo users from CSV file');

    // Create the migrate source.
    $import_path = drupal_get_path('module', 'foo_migrate') . '/import/users.csv';
    $options = array(
      'header_rows' => 1,

    $this->source = new MigrateSourceCSV($import_path, array(), $options);
    $this->destination = new MigrateDestinationUser();

    $this->map = new MigrateSQLMap($this->machineName,
          'Title' => array(
            'type' => 'varchar',
            'length' => 15,
            'not null' => TRUE,
            'description' => 'Title',
          'Firstname' => array(
            'type' => 'varchar',
            'length' => 35,
            'not null' => TRUE,
            'description' => 'First name',
          'Lastname' => array(
            'type' => 'varchar',
            'length' => 35,
            'not null' => TRUE,
            'description' => 'Last name',
          'Primary email address' => array(
            'type' => 'varchar',
            'length' => 80,
            'not null' => TRUE,
            'description' => 'Primary email address',

    // Mapped fields

    // We must have a unique username in the Drupal 'users' table.
    // dedupe() takes the Drupal table and column for determining uniqueness.
    $this->addFieldMapping('name', 'Primary email address')
         ->dedupe('users', 'name');
    $this->addFieldMapping('mail', 'Primary email address')
         ->dedupe('users', 'mail');

    //$this->addFieldMapping('pass', 'password');

    // Apply default role.

    $this->addFieldMapping('field_user_first_name',      'Firstname');
    $this->addFieldMapping('field_user_last_name',       'Lastname');




   * Modifies the row to be imported.
   * @inheritdoc
  public function prepareRow($row) {
    return parent::prepareRow($row);


The CSV data is like:

"Title","Firstname","Lastname","Primary email address"
"Mr","Foo","Bar","[email protected]"
"Mrs","Bar","Foo","[email protected]"

1 Answer 1


The 'Column not found' (map.sourceid4) error sounds like migration table related to source mapping is not complete.

You should identify the table (e.g. using drush command):

drush sqlq "SHOW TABLES LIKE 'migrate_map_%'"

Note: You can also execute above in SQL editor by using quoted part only.

and check the list of available columns for that table:

$ drush sqlq "DESC migrate_map_foomigrateusers"
sourceid1   varchar(128)    NO  PRI NULL
sourceid2   varchar(128)    NO  PRI NULL
sourceid3   varchar(128)    NO  PRI NULL
destid1 int(10) unsigned    YES     NULL
needs_update    tinyint(3) unsigned NO      0
rollback_action tinyint(3) unsigned NO      0
last_imported   int(10) unsigned    NO      0
hash    varchar(32) YES     NULL

The number of sourceidX column should match with number of columns in CSV file. If they won't, probably you've modified the CSV file and after each structure change you have to re-register your migration class (see: hook_migrate_api).

So please reregister any statically defined migration classes by (check list by drush ms):

drush migrate-deregister FooMigrateUsers
drush migrate-register FooMigrateUsers

In case of further problems, these drush commands can be handy as well:

drush migrate-mappings --all # To verify mapping.
drush migrate-fields-source --all # To list source field mapping.

When ready, try re-importing the data again:

drush mi FooMigrateUsers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.