askmatt

March 2, 2010

Base table or view already exists: 1050 Table already exists – Upgrade 1.3.2.4 to 1.4.0.1 failed – How to fix

Filed under: e-commerce — Tags: , — askmatt @ 1:26 am

After several unsuccessful attempts to upgrade from Magento 1.3.2.4 to 1.4.0.1 I have finally accomplished the upgrade by installing a fresh version on Magento 1.4 and then switching the name of the database to the 1.3.2.4 version, but you will need to make a few modifications to the Mysql upgrade files to get this to work.

You should make sure you have a backup of your Magento store and database before you do try any of this!

The original Magento install was in the ‘/var/www’ directory on my server, I created a new directory ‘/var/magento14′ and installed Magento V1.4 in there.

mkdir /var/magento14

cd /var/magento14

svn checkout http://svn.magentocommerce.com/source/branches/1.4

I then created a sub-domain, ‘ww2.mydomain.com’ and set the document root to ‘/var/magento14′, restarted apache and went through the installation routine by browsing to ‘http://ww2.mydomain.com/’. I set up the new Magento site to use a new database, no attempt to upgrade was made at this stage.

I then made a backup of the clean install database using ‘mysqldump’ so that I could always restore to this point without going through the installation process again.  You can check the differences between the 1.3.2.4 to 1.4.0.1 using Mysqldiff, at this point I did try to just upgrade my original 1.3 database but the upgrade failed because some data is moved into different tables.

For some reason the Magento upgrade routine tries to create some tables that already exist and this prevents the site from running.  I don’t know why these tables already exist maybe it is because the upgrade had already started to run and failed before completing, however forum threads here and here suggest that the upgrade routine is broken.

If you try and view your new 1.4 site now by visiting ww2.mydomain.com you will probably get an error, the only way to see this error is to view the files in ‘/var/magento14/var/reports/’ all the files have unique numbers, so enter ‘cat /var/magento14/var/reports/999999999999999′ (changing to the number on the error page!) to view the error.

The file will probably contain an error like this:

“Error in file: “/var/magento14/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-0.7.73-1.4.0.0.0.php” – SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘catalog_eav_attribute’ already exists

All these errors can be fixed by replacing all instances of ‘CREATE TABLE’ with ‘CREATE TABLE IF NOT EXISTS’. You can edit the files by hand or do them all at one with this command:

perl -pi -w -e 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g;' /var/magento14/app/code/core/Mage/Catalog/sql/catalog_setup/*.php

Have another look at the site and you will probably get 2 more errors, check your error logs and see if they relate to ‘mysql4-upgrade-0.8.18-0.8.19.php’ and ‘mysql4-upgrade-0.8.19-0.8.20.php’. If they do then you need to rename both of these files to stop them running.

mv /var/magento14/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php /var/magento14/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.18-0.8.19.php.dnr
mv /var/magento14/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php /var/magento14/app/code/core/Mage/Core/sql/core_setup/mysql4-upgrade-0.8.19-0.8.20.php.dnr

If you get any more errors such as the one below, look at the file that has the error and replace ‘CREATE TABLE’ with ‘CREATE TABLE IF NOT EXISTS’.

“Error in file: “/var/www/app/code/core/Mage/Cms/sql/cms_setup/mysql4-upgrade-0.7.11-0.7.12.php” – SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘widget’ already exists.

Now your site should be running again!

Copy the media files from your old version and set the correct permissions, test and then copy all the files to your live site.

**UPDATE**

The site seems to be working but a few category pages have the dreaded …

There has been an error processing your request

Exception printing is disabled by default for security reasons.

Error log record number: 00000000000000

Looking at the error logs, the exact error is:

a:5:{i:0;s:162:”Warning: Invalid argument supplied for foreach()  in /var/magento14/app/design/frontend/mystore/default/template/catalog/product/list/toolbar.phtml on line 51″;i:1;s:4565:”#0 /var/magento14/app/design/frontend/mystore/default/template/catalog/product/list/toolbar.phtml(51): mageCoreErrorHandler(2, ‘Invalid argumen…’, ‘/var/magento14/…’, 51, Array)

Seems there is a fix here, I will try that tomorrow.

Powered by WordPress