I'm using migrate module in Drupal 7 to update existing content of a Drupal site. My source and destination tables are the same. I got some documentation from http://drupal.org/node/1117454. Here's my code:
<?php
class MTestMigration extends Migration {
public function __construct() {
parent::__construct();
$this->systemOfRecord = Migration::DESTINATION;
$this->team = array(
new MigrateTeamMember('foo', '[email protected]', t('Site builder')),
);
$this->description = t('Migrate basic slides');
$source_fields = array(
'nid' => t('The node ID of the slide'),
'title' => t('The node title of the slide'),
'uri' => t('the slide image'),
);
$q = db_select('node', 'n');
$q->leftjoin('field_data_field_image', 'i', 'i.entity_id=n.nid');
$q->leftjoin('file_managed', 'f', 'i.field_image_fid=f.fid');
$q->fields('n', array('nid', 'vid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'sticky', 'tnid', 'translate'))
->fields('f', array('uri'))
->condition('n.type', 'slide', '=');
$this->source = new MigrateSourceSQL($q, $source_fields);
$node_options = MigrateDestinationNode::options(LANGUAGE_NONE, 'filtered_html');
$this->destination = new MigrateDestinationNode('slide', $node_options);
$this->map = new MigrateSQLMap($this->machineName,
array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Unique Node ID',
'alias' => 'n',
)
),
MigrateDestinationNode::getKeySchema()
);
$this->addFieldMapping('is_new')
->defaultValue(TRUE);
$this->addFieldMapping('nid', 'nid');
$this->addFieldMapping('title', 'title');
$this->addFieldMapping('is_new')->defaultValue(TRUE);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('revision')->defaultValue(TRUE);
$this->addFieldMapping('revision_uid', 'uid');
$this->addFieldMapping('created', 'created');
$this->addFieldMapping('changed', 'changed');
$this->addFieldMapping('status', 'status');
$this->addFieldMapping('promote', 'promote');
$this->addFieldMapping('sticky', 'sticky');
$this->addFieldMapping('comment', 'comment');
$this->addFieldMapping('language')->defaultValue('und');
$this->addFieldMapping('path')->issueGroup(t('DNM'));
$this->addFieldMapping('pathauto_perform_alias')->defaultValue('1');
$this->addFieldMapping(NULL, 'name');
$this->addFieldMapping(NULL, 'vid');
$this->addFieldMapping(NULL, 'type');
$this->addFieldMapping(NULL, 'language');
$this->addFieldMapping(NULL, 'tnid');
$this->addFieldMapping(NULL, 'translate');
$this->addFieldMapping('field_image', 'uri')
->arguments(FILE_EXISTS_RENAME);
}
}
I end up with this error:
Column not found: 1054 Unknown column 'map.destid1' in 'field list': SELECT n.nid AS nid, n.vid AS vid, n.type AS type, n.language AS language, n.title AS title, n.uid AS uid, n.status AS status, n.created AS created, n.changed AS changed, n.comment AS comment, n.promote AS promote, n.sticky AS sticky, n.tnid AS tnid, n.translate AS translate, f.uri AS uri, map.destid1 AS migrate_map_destid1, map.needs_update AS needs_update FROM {node} n LEFT OUTER JOIN {field_data_field_image} i ON i.entity_id=n.nid LEFT OUTER JOIN {file_managed} f ON i.field_image_fid=f.fid LEFT OUTER JOIN {migrate_map_mtest} map ON n.nid = map.sourceid1 WHERE (n.type = :db_condition_placeholder_0) AND (map.sourceid1 IS NULL OR map.needs_update = 1) ; Array ( [:db_condition_placeholder_0] => slide ) in MigrateSourceSQL->rewind()