WHMCS Upgrade Failure: Unable to complete incremental updates
While attempting to upgrade WHMCS version 5.x to 7.x, I kept getting MySQL errors from the updater script, and here’s how I was able to fix it.
The Errors
The first few errors I kept getting looked like this, saying table tblupdatehistory already exists:
1 |
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tblupdatehistory' already exists |
So as you would think, I just went ahead and dropped that table, but then one after another I kept getting errors about the created_at and updated_at columns already existing, something like this:
1 |
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' |
The Problem
The problem stems from the fact that WHMCS doesn’t care enough to spend the time to write a sql script that will actually check if those columns, or tables exist, before running the commands. Basically that means, if you have any type of error during your upgrade, they EXPECT YOU to restore a copy of the database, instead of writing a sql script that actually checks for columns before attempting to ALTER the table and add the column. So as usual, I had to come up with my own solution to their sloppy sql scripts.
The Solution
To determine the exact solution I needed to come up with, I had to inspect the sql upgrade file they were trying to import that was throwing the errors. The specific file ended up being the upgrade600alpha1.sql file, that’s where I found the MySQL code that was attempting to ALTER the table and ADD COLUMN without actually checking if the column already exists (that’s after the code that attempts to add the tblupdatehistory table without checking that it exists).
In order to get the upgrade to complete all the way, I had to literally fix each error one at a time as it showed on the upgrade page, and at the end, this is the MySQL code I had to run through phpMyAdmin to get past those errors:
1 2 3 4 5 6 7 8 9 10 11 12 |
DROP TABLE tblupdatehistory; DROP TABLE tblproduct_downloads; DROP TABLE tblproduct_upgrade_products; ALTER TABLE tblclients DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblconfiguration DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tbldownloadcats DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tbldownloads DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblemailtemplates DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblnetworkissues DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblproductgroups DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblproducts DROP COLUMN created_at, DROP COLUMN updated_at; ALTER TABLE tblservers DROP COLUMN port; |
As you can see, I first drop the tables that are created by the upgrade database file, then drop the columns that are added by that file as well. You will notice that the port column is also dropped, as this is added by the MySQL import as well. Once I did this, and resolved a few other issues (I also had to add userid column to tblinvoiceitems as well), and voila! Profit!
If you want to see what tables have a specific column in them, you can run this command and it will return the tables the column is found in:
1 |
SELECT * FROM information_schema.columns WHERE column_name = 'created_at'; |
Example Errors
1 2 3 4 5 6 |
[WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/account/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tblproduct_upgrade_products' already exists [WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/sheriff/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tblproduct_downloads' already exists [WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/sheriff/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'tblupdatehistory' already exists [WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/sheriff/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'userid' doesn't exist in table [WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/sheriff/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' [WHMCS Installer] ERROR: Unable to complete incremental updates: Unable to import the 6.0.0 Alpha1 database file. Unable to import /home/sheriff/public_html/resources/sql/upgrade600alpha1.sql: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'updated_at' |
-
Andry