Magento – Fatal error: Call to a member function getIdFieldName() on a non-object in abstract.php on line 151

fatal errormagento-1.9modelPHP

Magento ver. 1.9.2.0

I have recently setup a clone staging environment of my live site for testing purposes. The backend and front-end home & other pages are loading fine. Except when I browse product pages, I see the following error

Fatal error: Call to a member function getIdFieldName() on a
non-object in html/app/code/core/Mage/Core/Model/Abstract.php on line
151

See image below for reference.

enter image description here

Things that I have tried:
I have re-copied the html/app/etc/config.xml file from live to staging via FTP. Didn't work

Please help.
Thanks!

Best Answer

This issue could be due to different reasons.

1 - Firstly start by cleaning your cache and check.

2 - Then make sure you have not disabled Mage_log as described here

To do that you execute this in your magento docroot:

grep -A 5 -r '<Mage_Log>' app/etc/modules

You should see something like this:

<Mage_Log>
        <active>true</active>
        <codePool>core</codePool>

Next check in the admin panel in

System->Configuration->Advanced->Advanced

see if the module output is enabled there as well.

3 - Finally this issue happens when there is no resource defined for a given Model. To find out which is the Model that is failing you can add a log to this file:

app/Mage.php in line 254.

It should look like this:

public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }

    Mage::log(self::$_registry[$key], 1, 'issue.log');
    return null;
}

Then you can check your log file in here: var/log/issue.log

Or if you want to do it quick and dirty do it like this:

public static function registry($key)
{
    if (isset(self::$_registry[$key])) {
        return self::$_registry[$key];
    }

    die(self::$_registry[$key]);
    return null;
}

Make sure to revert the code changes once you find the issue.