I'm using migrate module 7.x-2.5 with a MySQL source database. My records are defined by the intersection of two tables, so I need two keys in my $source_key parameter to MigrateSQLMap(). I've done this before, no problem. But in this case, the columns have the same name, both "id". Because the column name is used as the key in the $source_key array, the second "id" would replace the first "id".

I tried defining an alias for one of the columns with addExpression() and using the alias (type_id) as one of the keys. This correctly registers multiple source keys and shows the correct record count on drush ms, but fails on drush mi with a SQL error: "Column not found: 1054 Unknown column 'type_id' in 'on clause'".

In the short term, I can just create a new column in one of the tables and duplicate the "id" values, but I'd like to know if there's a way to do this entirely in migrate code without altering the source database.

1 Answer 1


I'm not aware of a solution without altering the source database -- although there are in my opinion clean ways of altering the source DB; and it's not a ton of code:

In either your migration module hook_install() function or a pre/post Import hook call (https://drupal.org/node/1343112) simply using a custom db_query() such as:

db_query("CREATE TABLE foo LIKE other_table; INSERT INTO foo FROM (intersection query); ALTER TABLE foo (change id to type_id);");

You can drop/recreate the table as apart of a pre/post import call.

You just have to get the SQL right and it's all of 3 SQL statements, and 1 or 2 Drupal hook functions to make it all repeatable using Migrations.

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.