How to Perform a Direct Upgrade from Drupal 4.6.x to Drupal 6.x
This method will show you how to perform a direct website upgrade from Drupal 4.6.x to 6.x without having to perform the typical 4.6.x to 4.7.x to 5.x to 6.x version by version upgrade.
Why Use an Alternative Upgrade Method?
I did not want to perform the typical 4.6.x to 4.7.x to 5.x to 6.x version upgrade because of the following reasons:
- The possibility of loosing and corrupting data.
- The final upgraded database could end up containing residual and obsolete data from unused tables and fields from the version to version upgrade.
- The main reason for I chose this alternative method was that most of the content in my website had internal reference links to other pages in the site, and therefore I wanted to ensure that the upgrade would retain all the page, forum, node, and comment reference link numbers. Plus, I had about 800 users who have posted forum topics within the site and wanted to make sure that the user / posting references were retained properly.
Direct 4.6.x to 6.x Upgrade Procedure and Utility
The following Microsoft Excel utility can be use to create properly formatted CSV import files for importing tables into your 6.x database via phpMyAdmin. You can import the CSV files using phpMyAdmin's default CSV import option. The utility contains the following Drupal 6.x database table templates:
- users_roles, profile_fields, profile_values, users, term_node, forum, node, and comments
Download: http://xlecom.com/downloads/Direct_4_6_x_to_6_x_Updrade_Utility.zip
Direct 4.6.x to 6.x Upgrade Procedure
The following outlines the procedures I used to perform a successful direct 4.6.x to 6.x version upgrade. The upgraded website is http://xlecom.com.
I installed a new Drupal 6.9 installation into a subdirectory and setup the site with the basic format and theme settings. I did not add any content or blocks.
I then used phpMyAdmin for the database editing environment to export the 4.6.5 tables and re-import the modified tables back into the 6.9 database.
It was not easy. I hade to first export the key data Drupal 4.6.5 database tables individually, then alter them in Microsoft Excel to match the database table field structure of Drupal 6.x so that I could import them into the Drupal 6.9 database.
The following are the database tables that needed to be imported into Drupal 6.9 and the order they were imported.
# Database Table Excel Modifications Imported into 6.9 Database
-- ----------------------- --------------------------- --------------------------------------
00 users_roles * 00_ users_roles 6.x.xls 00_ users_roles 6.x.csv
01 profile_fields 01_ profile_fields 6.x.xls 01_ profile_fields 6.x.csv
02 profiles_values 02_ profile_values 6.x.xls 02_ profile_values 6.x.csv
03 users 03 users 6.x.xls 03 users 6.x.csv
04 term_data - No Conversion needed - 04_term_data.csv 6.x.zip
05 term_hierarchy - No Conversion needed - 05_term_hierarchy 6.x.csv.zip
06 term_node 06_term_node 6.x.xls 06_term_node 6.x.csv
07 forum 07_forum 6.x.xls 07_forum 6.x.csv
08 node_access - No Conversion needed - 08_node_access 6.x.csv.zip
09 node_comment_statistics - No Conversion needed - 09_node_comment_statistics 6.x.csv.zip
10 node_counter - No Conversion needed - 10_node_counter 6.x.csv.zip
11 node 11_node 6.x.xls 11_node 6.x.csv
12 node_revisions ** 12_node_revisions.csv.zip
13 comments ** 13 comments 6.x.xls 13 comments 6.x.csv
* The users_roles table in Drupal 6.9 did not have any defined roles in this table (an empty table), so I skipped it.
** Both the node_revisions and comments tables needed extra work to make them compatible with the Drupal 6.x format.
I had to first import the node and comments tables from Drupal 4.6.5 directly into Drupal 6.9 as temporary node1 and comments1 tables and then modify the table structures in Drupal 6.9 to match the node_revisions and comments table format. I then exported the node1 and comments1 table data as CSV files and re-imported the data back into the database into the node_revisions and comments tables. Lastly, I deleted (dropped) the temporary node1 and comments1 tables.
Explanation for New Users
You should have database access through your website's hosting control panel, not via your Drupal site itself. This database access tool is called phpMyAdmin.
Assuming you have both the old Drupal 4.6.x site's database file and the new Drupal 6.x database file on the same web server, when you activate phpMyAdmin, you should be able to open both of the Drupal database files and see the tables inside the database. You may want to open two instances of phpMyAdmin so that you can open both databases at the same times so you can visually see the differences in the tables.
The database is made up of a series of tables, where each table is set up as rows and columns, just like a spreadsheet.
If you look at the both the database tables from your old site and new site, you will see that some of the new drupal database tables have new added fields columns and some of the field names have changes.
If you follow the database table import / export instructions mentioned above,
"first export the key data Drupal 4.6.5 database tables individually, then alter them in Microsoft Excel to match the database table field structure of Drupal 6.x so that I could import them into the Drupal 6.9 database"
then your old 4.6.x site will be directly upgraded to Drupal 6.x.
If you export the key 4.6.x tables mentioned above using the format and use the supplied spreadsheet utility I made, then you can easily convert the old 4.6.x tables the new 6.x table format. The spreadsheet utility will allow you to create a CSV table file that you can import into the Drupal 6.0 database.
Just go to each of the database tables, one by one, and perform the conversion. The import CSV files should not contain the field names. You may also want to empty the Drupal 6.x tables just before you import the new table data so that the data you import is not added to any current data in the tables.
Note: when you perform the modification on the forums and term_node tables, make sure the values in the vid and nid columns are identical, meaning that they match (vid 1 = nid 1).
After each table export / import operation, backup the Drupal 6.x database in case you happen to do something wrong.
Use this Excel utility to Convert the Database table data to CSV format for Importing into a MySQL Database table via phpMyAdmin.
Important Warning
One important message for others who may attempt to do the same type of upgrade.
MySQL 4.x and PHP 4 only scripts will render your new site completely useless if running MySQL 5.x and PHP 5.
(1) Do not transfer any custom PHP block scripts into your new site without first testing them out in a test node page using PHP 5. The node Preview feature will help you debug your scripts before saving them to the database.
(2) If you had any custom PHP 4 only scripts within your old site, via the nodes (pages, forums, comments, etc...), and transferred them to the new site, then your site will get fatal errors during cron runs. This was the hardest thing for me to determine and debug to what was causing these fatal errors.
Optional MySQL Database SQL Character Substitutions
After I upgraded I noticed that some of the characters in the node and comments within the site were translated to some other format. I identified these characters and performed an SQL replacement to restore the characters back to normal. The replacements were performed on the database via SQL within phpMyAdmin.
Below are the SQL commands for the character replacements:
SQL Replace Statement
=====================
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
SQL Replacement Code to run within phpMyAdmin
=============================================
” = " (double quotes)
---------------------
update node_revisions set body = replace(body, '”', '"');
update node_revisions set teaser = replace(teaser, '”', '"');
update node_revisions set title = replace(title, '”', '"');
update comments set subject = replace(subject, '”', '"');
update comments set comment = replace(comment, '”', '"');
’ = ' (single quote)
----------------------
update node_revisions set body = replace(body, '’', ''');
update node_revisions set teaser = replace(teaser, '’', ''');
update node_revisions set title = replace(title, '’', ''');
update comments set subject = replace(subject, '’', ''');
update comments set comment = replace(comment, '’', ''');
†= " (double quotes)
-----------------------
update node_revisions set body = replace(body, 'â€', '"');
update node_revisions set teaser = replace(teaser, 'â€', '"');
update node_revisions set title = replace(title, 'â€', '"');
update comments set subject = replace(title, 'â€', '"');
update comments set comment = replace(comment, 'â€', '"');
“ = " (double quotes)
-----------------------
update node_revisions set body = replace(body, '“', '"');
update node_revisions set teaser = replace(teaser, '“', '"');
update node_revisions set title = replace(title, '“', '"');
update comments set subject = replace(subject, '“', '"');
update comments set comment = replace(comment, '“', '"');
• = • (bullet)
----------------
update node_revisions set body = replace(body, '•', '•');
update node_revisions set teaser = replace(teaser, '•', '•');
update node_revisions set title = replace(title, '•', '•');
update comments set subject = replace(subject, '•', '•');
update comments set comment = replace(comment, '•', '•');
â„¢ = ™ (trademark)
-------------------
update node_revisions set body = replace(body, 'â„¢', '™');
update node_revisions set teaser = replace(teaser, 'â„¢', '™');
update node_revisions set title = replace(title, 'â„¢', '™');
update comments set subject = replace(subject, 'â„¢', '™');
update comments set comment = replace(comment, 'â„¢', '™');
£ = £ (UK currency symbol)
---------------------------
update node_revisions set body = replace(body, '£', '£');
update node_revisions set teaser = replace(teaser, '£', '£');
update node_revisions set title = replace(title, '£', '£');
update comments set subject = replace(subject, '£', '£');
update comments set comment = replace(comment, '£', '£');
– = - (dash)
--------------
update node_revisions set body = replace(body, '–', '-');
update node_revisions set teaser = replace(teaser, '–', '-');
update node_revisions set title = replace(title, '–', '-');
update comments set subject = replace(subject, '–', '-');
update comments set comment = replace(comment, '–', '-');
Sam Raheb
Comments
?
You mentioned "I could not perform the typical upgrade ... due to the possibility of loosing and corrupting data" ... I've never heard of this issue before. Can you point to references/links about why this is a concern? As best I'm aware, Drupal 4.7.x is made to be upgraded to from Drupal 4.6.x, and so on, so it technically should work. Could you point us to the info you read about this? It must not be a "standard" issue for most people though, as of course every 4.6.x site passed through these upgrades to get to whatever version they are using today.
What I meant by"I could not
What I meant by
"I could not perform the typical upgrade, upgrading from 4.6.x to 4.7.x to 5.x to 6.x due to the possibility of loosing and corrupting data. Plus, most of the content in the site had reference links to other pages in the site, and therefore the upgrade would need to retain the same page / forum node numbers."
is that I could not afford to spend the time to find and debug errors if any would arise from upgrading from 4.6.x to 4.7.x to 5.x to 6.x. This upgrade path involves too many version upgrades and one may end up with the final database containing residual and duplicated data in unused table fields from the previous versions.
If one wants to perform the typical version by version upgrade, they can. I am just offering an alternative streamlined way to perform a direct upgrade from 4.6.x to 6.x upgrade.
Sam
error in node table during import process
Could you please elaborate on the changes you made to node_revisions to make it compatible.
I have tried to update my site the way you described. I exported all my tables from drupal 4.6 to 6.10.
The only trouble I had was the node table. Error: duplicate entry "0" for key "1". The problem was I could upload one row in the table but then every entry after that it would say duplicate because it would auto-increment the node, but not vid. and all the rows would be 0. So I switched them. I made the vid field the Primary Key and the nid, I took off the auto-imcrement value. I had success! I could import the entire old table and it matched with the node_revisions data.
The problem is that on the new site, I get the old error: duplicate entry "0" for key"2". Now the problem is that all the new entries have the node number of 0.
How do I solve this problem? Any suggestions would be awesome.
I have php 5.2.8
and mysql version 5.0.67
Okay, I figured it out. I
Okay, I figured it out. I changed the nid back to the primary key for the node table, and that solved everything. I think the problem was that I needed to get my nid in node and node_revisions identical as well as the vid. Then I needed to run a query found in http://drupal.org/node/313908 (just the last part about auto-increment) so those tables as well as the node_comment_statistics were on the same starting point. Now I am good to go.
Updating my site was so much better this way than upgrading through drupal because I avoided all the missing data and broken blocks and missing titles, etc. etc.
thanks for the guidance.
Glad it worked for you
Glad it worked for you.
If you downloaded my Direct 4.6.x to 6.x Upgrade Spreadsheet Utility (above), you would see how I arranged the data for importing into the 6.x website database.
Sam
Would you kindly explain exactly how to use your xls utility?
Sam, (or any other brilliant soul who will take pity on me)
I downloaded it, unzipped it, and read the instructions three times. It says, repeatedly, to "use this Excel utility to convert the database table to CSV format for importing..." but I have no idea what that means. Seriously. Not a clue. How does one "covert" something in Excel?
I really apologize for my ignorance, I haven't used Excel in well over a decade and I foolishly assumed a "utility" would be a little automated application. I hope you'll bare with me, because I'm really drowning in this drupal migration. I need directions for the excel-challenged, as in; click this menu, that command, etc. etc, because broad instructions like "convert" are totally lost on me.
Is it a matter of opening each 4.6 database table and cutting and pasting .... or "finding and replacing" ... exactly what into where? Or is there a command in Excel that executes the changes for me?
Hopeful and deeply appreciative of any help!
Eileen
RE: Would you kindly explain exactly how to use your xls utility
Eileen:
First of all you need to export each of the key MySQL database tables mentioned in the instructions into an Excel format. Use the phpMyAdmin table Export function and choose the Excel 2000 export format.
On each tabbed sheet within the Direct 4.6.x to 6.x Upgrade Excel workbook utility there are two tables laid out side by side where each of the tables are separated by a blank column. The table on the left (Table 1) contains the table data downloaded from the MySQL database. The table on the right (Table 2), the one with the "CSV Export" header title and values with blue colored fonts is the CSV conversion of the table on the left, Table 1. The blue colored values in Table 2 contain formulas that convert the values Table 1 into Comma Separated Values.
If you need more rows than what is provided in the sheets, then simply copy and paste the blue colored value cells in Table 2 downwards to create additional rows.
When you are done with editing the table data, then copy and paste the cells with the blue colored fonts, minus the "CSV Export" header title into an ASCII text file and save the text file with the CSV file extension. For example, users_roles 6.x.csv.
Switch back to phpMyAdmin and import the individual CSV files back into their corresponding database tables.
That's it.
If you need more help, just call me.
Sam