Magento Migration – Call to a Member Function setAttribute() on a Non-Object

magento-1.5magento-1.9migrationproductupgrade

I have migrated a magento store from 1.5 to 1.9 on my local server.(First migrated 1.5 to 1.6.2 then 1.6.2 to 1.9.1)

Now whenever i try to edit or add a new product following fatal error occurs.

Images : Image type and information need to be specified for each store view.

Fatal error: Call to a member function setAttribute() on a non-object in /var/www/html/monster_19/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php on line 366

This error also occurs on 1.6.2 staging version. Tried database repair tool also but problem still persist . And i don't want to hack into core. Please give solution.

Best Answer

Before trying anything, clear the cache. That might not help, but do it anyway.

The error is cause by this:

$this->_frontend = Mage::getModel($this->getFrontendModel())
            ->setAttribute($this);

this means Mage::getModel($this->getFrontendModel()) returns null (or false).
This can be caused by an attribute that has the field frontend_model set to something like [module]/something_here but the class [Namespace]_[Module]_Model_Something_Here does not exist.
You can identify the attribute by adding the following code above the line I mentioned:

$model = Mage::getModel($this->getFrontendModel());
if (!$model) {
    echo $this->getAttributeCode();exit;
}

You should see the attribute code in your page.
Then look in the eav_attribute table for this attribute and see if something is wrong with it. If you think the attribute is not needed anymore just delete it.