I have 3 non-drupal tables : items, item_actions, actions.

 items(id, title, body, published_at);   
 item_actions(item_id, action_id);   
 actions(id, name);   

I were able to migrate items to drupal 7. Now i want to migrate actions but since i don't know the node_id of the newly migrated items just the legacy id it is throwing an error.
How do i find the node_id knowing the legacy_id so that it finds the right node and migrate related content.

$query = Database::getConnection('default', 'for_migration')
  ->select('actions', 'actions')
  ->fields('actions', array('id', 'name'))
  ->orderBy('id', 'DESC');
// Join values from the action_items.
 $query->leftJoin('action_items', 'ai', '(actions.id = ai.action_id)'); 
 $query->addField('ai', 'item_id', 'item_list');    

Here is the error:

The referenced entity (node: 123456) is invalid.   

The migration was done with the migration module. So i had to write class migration and use queries like the one above to migrate to D7 the items table.
Can i create a table in the drupal DB and add the ids(old and new) for example: migrate_nodes(legacy_id, drupal_node_id) .
How do you capture the node_id?
I am new to drupal so this is still a learning process, thanks.

  • For getting help on this issue, please provide more details on how you migrated your non-Drupal entities. Did you create custom entities or do you use node types (bundles). Did you use custom code for migrating your entities or did you do so by using database queries? Provide your sources and the steps you conducted for migration, and you might get suggestions on how to rebuild your relations. As for now your description is too broad to give qualified answers without too much guessing. Commented Feb 8, 2016 at 3:34

1 Answer 1


How did you migrate the content from the nond-drupal tables to nodes? Module or custom code?

I would suggest a 'custom' migration routine/module (if it is a lot of data you can do this as a cron and/or batch job - that is a separate discussion).

Any case, in your custom routine, when you migrate each record (so read a record form your table and create a new node) from items and actions - you will be able to 'capture' the node id (nid) if the new node. Save this value to your 'old' items/actions tables (new field required). Now when you step through your item actions table you can use the nid saved in items and actions as reference values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.