Migrating nodes from Drupal 6 to 7

Sean Wragg
Jan 31, 2011 · 2 min read

(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.

:

  • 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.
  1. 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 7 settings.php. Naturally, you’ll need to replace the provided information with your connection information.
$databases['drupal6']['default']  (
  '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.

:

  • 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.

sean3z

Code, Comics, and Fhqwhgads!

Sean Wragg

Written by

Writing about code, comics, and fhqwhgads!

sean3z

sean3z

Code, Comics, and Fhqwhgads!