Magento CE 1.8.0.0 – sales_order Table Missing After Update

ce-1.8.0.0salesupgrade

I am trying to update magento ce-1.4.0.1 to ce-1.8. Problem is that magento converted the old database the sales_order is missing and because of this I can not enter the admin area.

Question is what is deleting the sales_order table?

I disabled all custom modules, renamed template folder, /app/code/community and /app/code/local to make sure they do nothing wrong. What I am doing is:

  • clear db
  • import my old db
  • update tables to InnoDB
  • enable logging ./n98-magerun.phar dev:log --on --global
  • switch index to realtime php shell/indexer.php --mode-realtime
  • clear cache: rm -fR var/*
  • call index.php

Before I call index.php sales_order does still exist. After that it's gone. What I am missing? How can I find what is causing this?

I assume changes in /skin and /media could not be related to this, right? There some changes in app/design still active. Is that bad?

I did a search for "dropTable" in Magento root but did not find something wired:

$ grep -R "dropTable" *
app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php:            $this->_getWriteAdapter()->dropTable($this->getFlatTableName($storeId));
app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php:        $_writeAdapter->dropTable($tableName);
app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php:            $this->_getWriteAdapter()->dropTable($this->getMainStoreTable($store));
lib/Varien/Db/Adapter/Interface.php:    public function dropTable($tableName, $schemaName = null);
lib/Varien/Db/Adapter/Pdo/Mysql.php:    public function dropTable($tableName, $schemaName = null)

Error message in /admin after convert:

a:5:{i:0;s:107:"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shop.sales_order' doesn't exist";i:1;s:4477:"#0 /lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT SUM((IFN...', Array)
#4 /lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('SELECT SUM((IFN...', Array)
#5 /lib/Zend/Db/Adapter/Abstract.php(734): Varien_Db_Adapter_Pdo_Mysql->query('SELECT SUM((IFN...', Array)
#6 /lib/Varien/Data/Collection/Db.php(734): Zend_Db_Adapter_Abstract->fetchAll('SELECT SUM((IFN...', Array)
#7 /app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(521): Varien_Data_Collection_Db->_fetchAll('SELECT SUM((IFN...', Array)
#8 /lib/Varien/Data/Collection/Db.php(566): Mage_Core_Model_Resource_Db_Collection_Abstract->getData()
#9 /app/code/core/Mage/Adminhtml/Block/Dashboard/Totals.php(70): Varien_Data_Collection_Db->load()
#10 /app/code/core/Mage/Core/Block/Abstract.php(261): Mage_Adminhtml_Block_Dashboard_Totals->_prepareLayout()
#11 /app/code/core/Mage/Core/Model/Layout.php(456): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
#12 /app/code/core/Mage/Adminhtml/Block/Dashboard.php(50): Mage_Core_Model_Layout->createBlock('adminhtml/dashb...')
#13 /app/code/core/Mage/Core/Block/Abstract.php(261): Mage_Adminhtml_Block_Dashboard->_prepareLayout()
#14 /app/code/core/Mage/Core/Model/Layout.php(456): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
#15 /app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('adminhtml/dashb...', 'dashboard')
#16 /app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('adminhtml/dashb...', 'dashboard')
#17 /app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#18 /app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#19 /app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#20 /app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#21 /app/code/core/Mage/Adminhtml/Controller/Action.php(275): Mage_Core_Controller_Varien_Action->loadLayout(NULL, true, true)
#22 /app/code/core/Mage/Adminhtml/controllers/DashboardController.php(40): Mage_Adminhtml_Controller_Action->loadLayout()
#23 /app/code/core/Mage/Core/Controller/Varien/Action.php(417): Mage_Adminhtml_DashboardController->indexAction()
#24 /app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#25 /app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#26 /app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#27 /app/Mage.php(683): Mage_Core_Model_App->run(Array)
#28 /index.php(118): Mage::run('', 'store')

Best Answer

The sales_order table and other tables related to sales are dropped in the upgrade script that changes the structure of the sales entities from EAV to flat.
The actual file is: app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php.
Near the end of the file there is this code:

// Remove previous tables
$tablesToDrop = array(
    'sales_order_entity_decimal',
    'sales_order_entity_datetime',
    'sales_order_entity_int',
    'sales_order_entity_text',
    'sales_order_entity_varchar',
    'sales_order_entity',
    'sales_order_decimal',
    'sales_order_datetime',
    'sales_order_int',
    'sales_order_text',
    'sales_order_varchar',
    'sales_order'
);

foreach ($tablesToDrop as $table) {
    $table = $installer->getTable($table);
    if (!$installer->tableExists($table)) {
        continue;
    }
    $installer->getConnection()->query(
        'DROP TABLE ' . $installer->getConnection()->quoteIdentifier($table)
    );
}

But the fact that they are dropped shouldn't be an issue. I think the problem comes from a custom module that uses the sales_order table directly, without wrapping it in ->getTable('sales/order'). or it is used like this ->getTable('sales_order').
I suggest disabling your custom modules first (specially those related to sales).
If I'm right and you upgrade you won't be able to use the module in question anyway.

[EDIT] And clear the cache after upgrade.

Related Topic