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:
<?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->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,
array(
'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',
),
),
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->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('roles')
->defaultValue(DRUPAL_AUTHENTICATED_RID);
$this->addFieldMapping('field_user_first_name', 'Firstname');
$this->addFieldMapping('field_user_last_name', 'Lastname');
$this->addUnmigratedSources(array('Title'));
$this->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","[email protected]"
"Mrs","Bar","Foo","[email protected]"