Hello, my name is Dan and I'm running a migration for a law firm into Drupal 6.20. I keep running into the same issue, though, and I was wondering if anyone could take a glance and maybe help me out.
I think the problem resides in how I'm defining the schema for the key on the source db (MySQL, local but in a separate db from Drupal, which may also be causing problems), but I haven't found much documentation as to how to define that schema, particularly in cases where the key is a varchar(50). If anyone could help me find docs on that, regardless of helping me solve my specific issue, I'd be very grateful.
Anyways, here's my module. This is the .inc I have:
class PAMigration extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrates \'Groups\' from the old data and makes them into new Practice Area nodes');
$query = db_select('acuweb_mmweb.groups', 'g')
->fields('g', array('UID', 'PracticeGroup', 'Description'));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationNode('practices');
$this->map = new MigrateSQLMap($this->machineName,
array(
'UID' => array(
'type' => 'varchar',
'length'=> 50,
'not null' => TRUE,
)
),
MigrateDestinationNode::getKeySchema()
);
// mapped source fields
$this->addFieldMapping('title', 'PracticeGroup')
->description(t('Mapping Practice Group name to the title of the node.'));
$this->addFieldMapping('body', 'Description')
->description(t('Mapping Practice Group description to the body of the node.'));
}
}
And the errors I'm recieving when I run drush migrate-import PA:
dan@dan-VirtualBox:/var/www/sites/all/modules/migrate$ drush migrate-import PA
Undefined property: stdClass::$UID
File /var/www/sites/all/modules/migrate/plugins/sources/sql.inc, line 354(file: /var/www/sites/all/modules/migrate/plugins/sources/sql.inc, line 354)PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'sourceid1' cannot be null' in /var/www/sites/all/modules/dbtng/database/database.inc:1964
Stack trace:
#0 /var/www/sites/all/modules/dbtng/database/database.inc(1964): PDOStatement->execute(Array)
#1 /var/www/sites/all/modules/dbtng/database/database.inc(562): DatabaseStatementBase->execute(Array, Array)
#2 /var/www/sites/all/modules/dbtng/database/mysql/query.inc(37): DatabaseConnection->query('INSERT INTO {mi...', Array, Array)
#3 /var/www/sites/all/modules/migrate/plugins/sources/sqlmap.inc(376): InsertQuery_mysql->execute()
#4 /var/www/sites/all/modules/migrate/includes/migration.inc(870): MigrateSQLMap->saveMessage(Array, 'SQLSTATE[23000]...', 1)
#5 /var/www/sites/all/modules/migrate/includes/migration.inc(465): Migration->saveMessage('SQLSTATE[23000]...')
#6 /var/www/sites/all/modules/migrate/includes/base.inc(798): Migration->import()
#7 /var/www/sites/all/modules/migrate/migrate.drush.inc(673) in /var/www/sites/all/modules/dbtng/database/database.inc on line 1964
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column
'sourceid1' cannot be null' in /var/www/sites/all/modules/dbtng/database/database.inc:1964
Stack trace:
#0 /var/www/sites/all/modules/dbtng/database/database.inc(1964): PDOStatement->execute(Array)
#1 /var/www/sites/all/modules/dbtng/database/database.inc(562): DatabaseStatementBase->execute(Array, Array)
#2 /var/www/sites/all/modules/dbtng/database/mysql/query.inc(37): DatabaseConnection->query('INSERT INTO {mi...', Array,
Array)
#3 /var/www/sites/all/modules/migrate/plugins/sources/sqlmap.inc(376): InsertQuery_mysql->execute()
#4 /var/www/sites/all/modules/migrate/includes/migration.inc(870): MigrateSQLMap->saveMessage(Array, 'SQLSTATE[23000]...',
1)
#5 /var/www/sites/all/modules/migrate/includes/migration.inc(465): Migration->saveMessage('SQLSTATE[23000]...')
#6 /var/www/sites/all/modules/migrate/includes/base.inc(798): Migration->import()
#7 /var/www/sites/all/modules/migrate/migrate.drush.inc(673) in /var/www/sites/all/modules/dbtng/database/database.inc, line
1964
Any help or at least point me in the right direction would be very helpful. Requests for further information will be honored if I can. Thank you in advance!
Comments
Comment #1
dhansen commentedThis issue is now fixed. It seems that it was just a case issue; the field mappings source column name needed to be all lowercase machine names for the mappings to be recognized and the key mapping in the MigrateSQLMap needed to have the definition array be labeled as a lowercase machine name as well. This is particularly odd as the db_select works just fine with the fields in their existing cases.
Maybe needs a slight modification in the docs where it says the key of the array matches the field name used in the query: http://drupal.org/node/1006984
Or perhaps better, maybe a little more liberal use of drupal_strtolower() in the module?
Comment #2
zoen commentedI ran into this very same issue (import failed "Undefined property: stdClass::FooBar" when field mapping source column names were given in mixed case) using Migrate in Drupal 7.
Comment #3
grendzy commentedThis issue is still present in 7.x-dev.
Comment #4
mikeryan@grendzy: Are you using lowercase in your field mappings? This is necessary, because Drupal lower-cases the field names as they're returned from the DB.
Comment #5
grendzy commentedGot it, thanks. I was thinking the column would all have to be renamed, but it seems this isn't the case.
Comment #6
mototribe commentedI ran into that problem too, would be great to have a comment added to the example files.
Comment #7
mikeryanThe lower-case issue is being fixed in Drupal core: #1171866: Enforced fetching of fields/columns in lowercase breaks third-party integration.