Hi,
I'm trying to setup a migration between two different database (D5 -> D6) but am struggling to get it to work. I looked at #828288: Importing from a different database connection to try and get it going with no luck. In my migrate class right now I have:
$this->map = new MigrateSQLMap(
$this->machineName,
array(
'style' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'D5 Unique user ID',
),
),
MigrateDestinationUser::getKeySchema(),
'd5_db'
);
The d5_db is the source database. And is configured in settings.php on the d6 site that I'm running the script from.
$query = db_select('users', 'u')
->fields('u', array('name', 'pass', 'mail'));
$this->source = new MigrateSourceSQL($query);
$this->destination = new MigrateDestinationUser();
However, I get an error with this:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'd5_db.migrate_map_d5userobject' doesn't exist' in ...
Since I'm running the migrate code from within the destination site, I would have thought that it would only create the migrate_map tables in the destination site (which is what it seems to be doing). But for some reason it's looking for them in the source database.
Any ideas on what I can do to get around this?
Thanks!!
Scott
Comments
Comment #1
hadsie CreditAttribution: hadsie commentedOk, I think I've figured this one out...
The migrate map remains the same whether connecting to a table in this database versus a table in an external database.
getConnection must have the d5_db set. Note that this must also be configured in settings.php, like so:
I think we need a custom count query to access the external database.
Finally, the source must have the map_joinable parameter set to FALSE so it doesn't try to join against the drupal database.
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedAny chance you can turn this into a patch for README.txt (Multiple DB connections)?
Comment #3
Ivo.Radulovski CreditAttribution: Ivo.Radulovski commentedHello,
struggling too here...
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mglegacy1.migrate_map_mgterm' doesn't exist' in...
mglegacy1 is the source database
followed the steps above... and additionally I've got this....
comes from here...
$this->source = new MigrateSourceSQL($query, array(), $count_query, FALSE);
Any Ideas?
Thanks,
Ivo
Comment #4
fangel CreditAttribution: fangel commentedI use the easy way out - a single database-connection that allows access to both databases, and then using database.table when constructing the db_select()
Ie.
So you might want to check if that option is available to you too (that is, accessing the old database from your current Drupal database connection) instead of trying to use multiple database-connections..
Comment #5
Ivo.Radulovski CreditAttribution: Ivo.Radulovski commentedThanks!
This works for me!
Additionally i resolved the problem with using multiple database-connections
I was looking into the other errors...but it is obvious that something was wrong here
So i changed the code according to the error message to
It works! :=)
Thanks,
Ivo
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedFYI, I have been using this "period trick" a lot and it works nicely on mysql. I fought to preserve this feature in Drupal 7 as it was impossible for a little while #715132: Over aggressive escaping of table names. Note that the period technique is better than setting mapJoinable = FALSE since those map joins improve efficiency a lot.
We need some better docs here. Anyone up for a README.txt patch?
Comment #7
Ivo.Radulovski CreditAttribution: Ivo.Radulovski commentedThanks!
When we write up some documentation for the client I will try to gather some info for the docs!
Regards,
Ivo Radulovski
www.drupal.bg/en
Comment #8
mikeryanRather than README.txt, let's work detailed documentation like this into the module documentation on d.o, which is finally taking shape. I've created a page for this subject: http://drupal.org/node/1014558
Comment #9
BTMash CreditAttribution: BTMash commentedI was going through this for a project I'm migrating from Drupal 6 to Drupal 7 and I found that using Database::getConnection requires for the target and key to be flipped - I've added a comment at http://drupal.org/node/1014558#comment-4105852
EDIT: nvm - I think I had my thing idea flipped..
Comment #10
Blackice2999 CreditAttribution: Blackice2999 commentedHi,
the issues are a littlebit confusing me so i write down here my experience with two databases and hope it helps some.
first i defined the second database in drupal settings.php like this:
in my migration class (node migration) i used following SQLMap
this way works perfekt for me. I can get the source from the Joomla Database and the mapping also works fine.
regards
Dennis
Comment #11
mikeryanOK, I've updated http://drupal.org/node/1014558 based on input from @drewish and @BTMash - how does that look?
Comment #12
mikeryanComment #14
rfayI still had quite a lot of trouble navigating this, so created an example, #1210064: Provide a cross-db migration example
Comment #15
ermannob CreditAttribution: ermannob commentedHello Mike,
I'm sorry, but I can't see any improvement on that page...
I found a solution for my problem only looking at this issue. I'm working on two DBs on the same server. Drupal 6.
#4 saved my day.
Thanks.
-ermannob