Unknown map column when migrating users from CSV file 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:

&lt;?php

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

/**
 * Class FooMigrateUsers.
 */
class FooMigrateUsers extends Migration {


  /**
   * Constructor.
   *
   * @inheritdoc
   */
  public function __construct($arguments) {
    parent::__construct($arguments);
    $this-&gt;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' =&gt; 1,
    );

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

    $this-&gt;map = new MigrateSQLMap($this-&gt;machineName,
        array(
          'Title' =&gt; array(
            'type' =&gt; 'varchar',
            'length' =&gt; 15,
            'not null' =&gt; TRUE,
            'description' =&gt; 'Title',
          ),
          'Firstname' =&gt; array(
            'type' =&gt; 'varchar',
            'length' =&gt; 35,
            'not null' =&gt; TRUE,
            'description' =&gt; 'First name',
          ),
          'Lastname' =&gt; array(
            'type' =&gt; 'varchar',
            'length' =&gt; 35,
            'not null' =&gt; TRUE,
            'description' =&gt; 'Last name',
          ),
          'Primary email address' =&gt; array(
            'type' =&gt; 'varchar',
            'length' =&gt; 80,
            'not null' =&gt; TRUE,
            'description' =&gt; 'Primary email address',
          ),
        ),
        MigrateDestinationUser::getKeySchema()
        );

    // Mapped fields

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

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

    // Apply default role.
    $this-&gt;addFieldMapping('roles')
         -&gt;defaultValue(DRUPAL_AUTHENTICATED_RID);

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

    $this-&gt;addUnmigratedSources(array('Title'));

    $this-&gt;addUnmigratedDestinations(array(
      'access',
      'created',
      'data',
      'is_new',
      'language',
      'login',
      'pass',
      'picture',
      'role_names',
      'signature',
      'signature_format',
      'theme',
      'timezone',
    ));

  }

  /**
   * 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","foo@example.com"
"Mrs","Bar","Foo","bar@example.com"
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