Migrating nodes from Drupal 6 to 7
(attow) Sadly, there doesn’t seem to be a straight forward method for importing content nodes from Drupal 6 to Drupal 7 without installing a module. Albeit, this isn’t the “best” method but hopefully, this snippet will at least assist in filling the void. There are a few caveats however.
Forewarning:
- This snippet requires the use of Node 1 but, can be replaced/removed after import.
- This snippet will reorder your Node IDs (nids) but, will keep your URL aliases intact.
- This snippet only imports “page” content types but, can easily be modified for others.
- First, you’ll need to add your Drupal 6 database to the Druapl 7
$databases
array. We accomplish this by modifying then appending the following code to our Drupal 7settings.php
. Naturally, you’ll need to replace the provided information with your connection information.
$databases['drupal6']['default'] = array(
'driver' => 'mysql',
'database' => 'database',
'username' => 'username',
'password' => 'password',
'host' => 'hostname',
'prefix' => '',
);
- Enable the PHP Filter module. (if not already enabled)
- Clear Drupal 7 Cache
- Replace Node 1 (yoursite.com/node/1) or Create your first Basic Page node. Title the node as you wish, select the Text format as “PHP Code”, then paste the following code within the body.
- Visit yoursite.com/node/1 and click “Import Nodes”. It may take a few minutes depending on how many nodes being imported.
Troubleshooting:
- If you receive the error “PDOException: SQLSTATE[42000] [1049] Unknown database…” double check your database connection in
settings.php
then try clearing the Drupal 7 cache.