Migrating data from Drupal 6 to Drupal 7

One of our clients is redeveloping the front-end of their site and wanted to take the opportunity to upgrade from Drupal 6 in the process. As the basic data structure was to remain the same, it made sense to go for a straight upgrade, following the instructions in the UPGRADE.txt file from Drupal 7.

After checking that all the modules on the original site were up to date, I did a quick site audit. All of the Drupal 6 modules used had a Drupal 7 version except for the attribute module. The attribute module lets you create a CCK field that contains an attribute:value pair, such as color:blue or size:large. This kind of functionality can be created in Drupal 7 using the field collection module, but would require a bit of work to migrate the data over.

The original site used features extensively. The built in Drupal upgrade path is designed around migrating data contained in the database, not in code. A quick look through the features issue queue provided this patch which adds an extra drush command to features – drush features-import-all. Running this moved all of the features into the database. I could then disable each of the custom features without losing any configuration data.

Continuing with the instructions in UPGRADE.txt, I quickly had Drupal core updated to version 7 together with all the contributed modules that had a Drupal 7 release. All the content types were still there, but missing lots of fields, which brings us to the next step – moving Drupal 6 CCK data to Drupal 7 fields. This is well covered in the Drupal handbook page, Migrating D6 Content Construction Kit (CCK) to D7 Fields.

By this point, all the old content was showing up in Drupal 7 apart from the attribute fields. The old CCK attribute field was called field_item_for_sale_glance and all the data was in the content_field_item_for_sale_glance table in the database.

I created a new field_collection, which I also called field_item_for_sale_glance, containing two text fields; field_sale_attribute_key and field_sale_attribute_value. After that, a quick bit of custom code was required to copy the data across.

We’re Code Enigma

We’re one of the most experienced Drupal teams in Europe, best known for our work on large, technically challenging projects for all kinds of clients.

Our team is passionate about Drupal and open source software. Our whole company spends at least four weeks per year working on Drupal modules or other open source projects. We’re also strongly committed to putting design first, taking a mobile-first, content-out approach to creating websites. This ensures that the sites we build combine the power of Drupal with best practice design and development.