Solving Magento “Undefined Index” error on Database Restore

If you’ve ever moved a Magento database from one server to another, perhaps taking a devel site live, you might have seen an error something like this:

a:2:{i:0;s:136:"Notice: Undefined index:  0  in /Library/WebServer/Documents/yoursite.com/app/code/core/Mage/Core/Model/Mysql4/Config.php on line 92";i:1;s:776:"#0 /Library/WebServer/Documents/yoursite.com/app/code/core/Mage/Core/Model/Mysql4/Config.php(92): mageCoreErrorHandler(8, 'Undefined index...', '/Library/WebSer...', 92, Array)
#1 /Library/WebServer/Documents/yoursite.com/app/code/core/Mage/Core/Model/Config.php(268): Mage_Core_Model_Mysql4_Config->loadToXml(Object(Mage_Core_Model_Config))
#2 /Library/WebServer/Documents/yoursite.com/app/code/core/Mage/Core/Model/App.php(263): Mage_Core_Model_Config->init(Array)
#3 /Library/WebServer/Documents/yoursite.com/app/Mage.php(434): Mage_Core_Model_App->init('', 'store', Array)
#4 /Library/WebServer/Documents/yoursite.com/app/Mage.php(455): Mage::app('', 'store', Array)
#5 /Library/WebServer/Documents/yoursite.com/index.php(65): Mage::run()
#6 {main}";}

This is Magento complaining about not finding the correct default website data. Now you might be thinking, “What’s the deal? I did a database dump and import…”

The problem is the import process to the new MySQL database.

MySQL defaults to an ID of 1. Unless explicitly told, it will silently change values of 0 to 1, thus breaking the site functionality.

To cure this problem, add this at the top of the database dump before importing:

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

This does just what it appears to do — tells MySQL to user 0 instead of it’s automatic value, which is usually 1.

I use Navicat, a wonderful SQL client. But it has this one little problem — it doesn’t add this particular useful phrase to the dump. By adding the above SQL command at the top of the file, a reimport fixes it. Problem solved.

Leave a Reply

You must be logged in to post a comment.