0

In some rare cases Magento doesn't add tables on installation, but it creates an entry in core_resource. This produces error

 Base table or view not found... 

If I delete core_resource entry it will go through sql install script again and this time it will add also tables and everything starts working again. I can not figure out when this happens, it happens just in some cases, sometimes if my customer uses FTP upload and sometimes if he/she install it through Magento Connect Manager.

I am wondering when exactly Magento adds core_resource entry. I thought it adds it once it completes sql installer script. But if this was true, then it would add sql tables OR it wouldn't add sql tables and it also wouldn't add core_resource entry.

2 Answers 2

1

My experience shows that if installing extensions manually, you HAVE to disable cache, otherwise often you end with this situation. Core resource is updated within the setup update method, but often times config cache screws things over.

2
  • It is true it happens more often if cache is enabled. But I just had this week a customer who had cache disabled and it happened the same.
    – JohnyFree
    Commented Nov 14, 2014 at 21:32
  • That is weird, if you want to trace this more in depth, look at Mage_Core_Model_Resource_Setup::_modifyResourceDb, that is where the whole thing happens. Commented Nov 14, 2014 at 21:43
0

I still didn't solve the original problem, but I bypassed the potential error with this code:

Frontend block:

$tableName = Mage::getSingleton("core/resource")->getTableName('mymodul_tablename');
$table = (boolean) Mage::getSingleton('core/resource')->getConnection('core_write')->showTableStatus(trim($tableName,'`'));
if(!$table){        
  Mage::log('Mymodule table does not exist');
  return array();
}

and inside admin in _prepareCollection

$tableName = Mage::getSingleton("core/resource")->getTableName('mymodul_tablename');
$table = (boolean) Mage::getSingleton('core/resource')->getConnection('core_write')->showTableStatus(trim($tableName,'`'));
if(!$table){
  $tableName = Mage::getSingleton("core/resource")->getTableName('core_resource');
  $sql = "DELETE FROM $tableName WHERE code = 'mymodulename_setup';";  
  $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
  try {
      $connection->query($sql);
  } catch (Exception $e) {
      echo $e->getMessage();
  }      
  echo 'Please refresh this page.'; 
  Mage::log('My module table does not exist');
  return;        
}   

In this way Magento will go through installation script again and add all tables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.