entityreference = 7.x-1.0-beta1
migrate = 7.x-2.2

I am migrating a series of blog posts from a custom CMS into Drupal 7 using the Migrate module. The tags import ok, but when it comes to importing the blog posts themselves the migration fails on the entity reference field (field_tags) with the following error:

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'Author - CEO' for column 'field_tags_target_id' at row 1: 
INSERT INTO {field_data_field_tags} 
(entity_type, entity_id, revision_id, bundle, delta, language, field_tags_target_id, field_tags_target_type) 
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); 
Array ( 
  [:db_insert_placeholder_0] => node 
  [:db_insert_placeholder_1] => 2564 
  [:db_insert_placeholder_2] => 2565 
  [:db_insert_placeholder_3] => blog 
  [:db_insert_placeholder_4] => 0 
  [:db_insert_placeholder_5] => und 
  [:db_insert_placeholder_6] => Author - CEO 
  [:db_insert_placeholder_7] => taxonomy_term 
) (/Users/garrettc/Work/sandbox/wdcs_import_test/modules/field/modules/field_sql_storage/field_sql_storage.module:424)

Looking at the array that's being passed to the INSERT, [:db_insert_placeholder_6] is being set to "Author - CEO" instead of the term ID.

Previously this field was a standard core term reference field which accepts the term name, so the import was working, but I moved to entityreference for the expanded feature set.

Is there a step that I'm missing in my migration code to handle an entityreference field? I searched for documentation but I could only find #1261086: Implements migrate handler which seems to imply that it should just work.

Comments

damien tournoud’s picture

The migrate handler expects a Term ID. Contrary to popular belief, the term name is *not* unique across terms (even of the same vocabulary), so it cannot be used to uniquely identify a term. The term field uses an heuristic to guess which term you are referencing.

The usual way of doing what you are after is to migrate the terms separately, and use ->sourceMigration() to map the original term names to IDs:

    $this->addFieldMapping('field_tags', 'legacy_tag_field')
         ->sourceMigration('MyTermMigration');
garrettc’s picture

Status: Active » Closed (fixed)

Ah, of course. Stupid mistake on my part. I'd used ->sourceMigration() for the author mapping, but forgot to add it to the tag mapping.