I get a constraint error for inserting a source ID into the node ID i want to create. I have run the query against the source DB and no duplicates are present.

This is the SQL that var dump shows:

SELECT videos.id AS id, videos.title AS title, videos.introtext AS introtext, videos.programa AS programa, videos.tipo AS tipo
FROM
{jos_content} videos
WHERE (tipo = :db_condition_placeholder_0)

class VideoNodeMigration extends BasicNovasurMigration {

  public function __construct() {
    parent::__construct();
    $this->description = t('Videos en Joomla');

    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'id' => array(
          'type' => 'int',
          'not null' => TRUE,
          'description' => 'Node ID.',
          'alias' => 'videos',
        )
      ),
      MigrateDestinationNode::getKeySchema()
    );

    $query = Database::getConnection('default','joomla')
      ->select('jos_content','videos')
      ->fields('videos', array('id','title','introtext', 'programa', 'tipo'))
      ->condition('tipo',1);

      $query->addField('videos', 'fulltext', 'joomla_body'); 

    $count_query = Database::getConnection('default', 'joomla')
      ->select('jos_content','videos')
      ->condition('tipo',1);
    $count_query->addExpression('COUNT(id)', 'cnt');

    // Create a MigrateSource object, which manages retrieving the input data.
    $this->source = new MigrateSourceSQL($query, array(), $count_query, array('map_joinable' => FALSE));

    $this->destination = new MigrateDestinationNode('video');

    $this->addFieldMapping('title', 'title');

    $this->addFieldMapping('body', 'joomla_body')
      ->arguments(array('format' => 'full_html'));
    $this->addFieldMapping('body:summary', 'introtext');

    $this->addFieldMapping('nid', 'programa')
         ->description(t('Preservar la ID del programa como id del nodo'));
    $this->addFieldMapping('is_new')
         ->defaultValue(TRUE);

    // No description for images, only alt and title
    $this->addUnmigratedSources(array('image_description'));

    // Unmapped destination fields
    $this->addUnmigratedDestinations(array('created', 'changed', 'status',
      'promote', 'revision', 'language', 'revision_uid', 'log', 'tnid',
      'body:format', 'body:language', 'migrate_example_beer_styles:source_type',
      'migrate_example_beer_styles:create_term', 'field_migrate_example_image:destination_dir',
      'field_migrate_example_image:language', 'field_migrate_example_image:file_replace',
      'field_migrate_example_image:preserve_files', 'field_migrate_example_country:language', 'comment',
      'field_migrate_example_image:file_class', 'field_migrate_example_image:destination_file'));

    if (module_exists('path')) {
      $this->addFieldMapping('path')
           ->issueGroup(t('DNM'));
      if (module_exists('pathauto')) {
        $this->addFieldMapping('pathauto')
             ->issueGroup(t('DNM'));
      }
    }
    if (module_exists('statistics')) {
      $this->addUnmigratedDestinations(array('totalcount', 'daycount', 'timestamp'));
    }
  }
}

When running drush migrate-import VideoNode I get the following:

WD node: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '908' for key 'PRIMARY': INSERT INTO {node} (nid, type, [error]
language, title, uid, status, created, changed, comment, promote, sticky) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10); Array
(
[:db_insert_placeholder_0] => 908
[:db_insert_placeholder_1] => video
[:db_insert_placeholder_2] => und
[:db_insert_placeholder_3] => La gran montaña rusa
[:db_insert_placeholder_4] => 0
[:db_insert_placeholder_5] => 1
[:db_insert_placeholder_6] => 1384905521
[:db_insert_placeholder_7] => 1384905521
[:db_insert_placeholder_8] => 2
[:db_insert_placeholder_9] => 1
[:db_insert_placeholder_10] => 0
)
in drupal_write_record() (line 7166 of /Users/tomasbarrios/Sites/drupal/clean-drupal/includes/common.inc).
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '908' for key 'PRIMARY': INSERT INTO {node} (nid, type, [error]
language, title, uid, status, created, changed, comment, promote, sticky) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10); Array
(
[:db_insert_placeholder_0] => 908
[:db_insert_placeholder_1] => video
[:db_insert_placeholder_2] => und
[:db_insert_placeholder_3] => La gran montaña rusa
[:db_insert_placeholder_4] => 0
[:db_insert_placeholder_5] => 1
[:db_insert_placeholder_6] => 1384905521
[:db_insert_placeholder_7] => 1384905521
[:db_insert_placeholder_8] => 2
[:db_insert_placeholder_9] => 1
[:db_insert_placeholder_10] => 0
)

ANY CLUE?? Thanks! Love migrate! :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tomasbarrios’s picture

Issue summary: View changes
13rac1’s picture

It's best if you don't set nid in the field mapping. Allow the migrate module to create new nids.

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

As eosrei, don't try to preserve the ID unless you really have a specific need to - leave 'nid' and 'is_new' unmapped. The most likely explanation for the problem here, since you've verified your incoming ids are unique, is that a Drupal node with that nid has been manually created.

13rac1’s picture

That's exactly what I said...?

mikeryan’s picture

As I was setting the status to Postponed, I figured I would elaborate a bit.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)