1

I am trying to upgrade my module table by using the upgrade script. I am getting the error Base table or view not found. Please, check below the config.xml file, install script and upgrade script code:

Config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Tandem_OenologistUser>
        <version>0.0.2</version>
    </Tandem_OenologistUser>
</modules>
<frontend>
    <routers>
        <oenologist>
            <use>standard</use>
            <args>
                <module>Tandem_OenologistUser</module>
                <frontName>oenologist</frontName>
            </args>
        </oenologist>
    </routers>
    <layout>
        <updates>
            <oenologist>
                <file>oenologist.xml</file>
            </oenologist>
        </updates>
    </layout>
</frontend>
<global>
    <blocks>
        <tandem_oenologistuser_adminhtml>
           <class>Tandem_OenologistUser_Block_Adminhtml</class>
        </tandem_oenologistuser_adminhtml>
    </blocks>

    <helpers>
        <tandem_oenologistuser>
            <class>Tandem_OenologistUser_Helper</class>
        </tandem_oenologistuser>
    </helpers>

    <models>
        <tandem_oenologistuser>
            <class>Tandem_OenologistUser_Model</class>
            <resourceModel>tandem_oenologistuser_resource</resourceModel>
        </tandem_oenologistuser>
        <tandem_oenologistuser_resource>
            <class>Tandem_OenologistUser_Model_Resource</class>
            <entities>
                <oenologist>
                    <table>tandem_oenologistuser_oenologist</table>
                </oenologist>
            </entities>
        </tandem_oenologistuser_resource>
    </models>

    <resources>
        <tandem_oenologistuser_setup>
            <setup>
                <module>Tandem_OenologistUser</module>
                <class>Mage_Core_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </tandem_oenologistuser_setup>
    </resources>

</global>

<admin>
    <routers>
        <tandem_oenologistuser_admin>
            <use>admin</use>
            <args>
               <module>Tandem_OenologistUser_Adminhtml</module>
                <frontName>oenologist-user-admin</frontName>
            </args>
        </tandem_oenologistuser_admin>
    </routers>
</admin>

install-0.0.1.php

<?php
$this->startSetup();

$table = new Varien_Db_Ddl_Table();

$table->setName($this->getTable('tandem_oenologistuser_oenologist'));

$table->addColumn(
'entity_id',
Varien_Db_Ddl_Table::TYPE_INTEGER,
10,
array(
    'auto_increment' => true,
    'unsigned' => true,
    'nullable'=> false,
    'primary' => true
)
);
$table->addColumn(
'created_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'updated_at',
Varien_Db_Ddl_Table::TYPE_DATETIME,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'name',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
    'nullable' => false,
)
);
$table->addColumn(
'email',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
    'nullable' => false,
)
);
$table->addColumn(
'url_key',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
    'nullable' => false,
)
);
$table->addColumn(
'description',
Varien_Db_Ddl_Table::TYPE_TEXT,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'visibility',
Varien_Db_Ddl_Table::TYPE_BOOLEAN,
null,
array(
    'nullable' => false,
)
);
$table->addColumn(
'customer_id',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
255,
array(
    'nullable' => false,
)
);
$table->addColumn(
'instagramid',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
500,
array(
    'nullable' => false,
)
);
$table->addColumn(
'facebookid',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
500,
array(
    'nullable' => false,
)
);
$table->addColumn(
'twitterid',
Varien_Db_Ddl_Table::TYPE_VARCHAR,
500,
array(
    'nullable' => false,
)
);

$table->setOption('type', 'InnoDB');
$table->setOption('charset', 'utf8');

$this->getConnection()->createTable($table);

$this->endSetup();

upgrade-0.0.1-0.0.2.php*

$installer = $this;
$connection = $installer->getConnection();

$installer->startSetup();

$installer->getConnection()
    ->addColumn($installer->getTable('tandem_oenologistuser/oenologist'),
    'customer_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255,
    array(
        'nullable' => true,
        'default' => null,
        'comment' => 'customer id'
    )
)
    ->addColumn($installer->getTable('tandem_oenologistuser/oenologist'),
    'instagramtoken', Varien_Db_Ddl_Table::TYPE_VARCHAR, 500,
    array(
        'nullable' => true,
        'default' => null,
        'comment' => 'instagram oauth token'
    )
)
    ->addColumn($installer->getTable('tandem_oenologistuser/oenologist'),
    'facebooktoken', Varien_Db_Ddl_Table::TYPE_VARCHAR, 500,
    array(
        'nullable' => true,
        'default' => null,
        'comment' => 'facebook oauth token'
    )
)
    ->addColumn($installer->getTable('tandem_oenologistuser/oenologist'),
    'twittertoken', Varien_Db_Ddl_Table::TYPE_VARCHAR, 500,
    array(
        'nullable' => true,
        'default' => null,
        'comment' => 'twitter oauth token'
    )
);

$installer->endSetup();

Table is present in database. Can I add columns manually?

4
  • you have to keep filename mysql4-upgrade-0.0.1-0.0.2.php Sep 15, 2016 at 7:47
  • nothing happened same error still Sep 15, 2016 at 8:01
  • PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 La table '255.tandem_oenologistuser_oenologist' n'existe pas in C:\wamp\www\wampserver\tandem\lib\Zend\Db\Statement\Pdo.php on line 228 Sep 15, 2016 at 8:01
  • old table already exists ? Sep 15, 2016 at 8:38

2 Answers 2

1

Keep below code in your mysql4-upgrade-0.0.1-0.0.2.php file,

<?php

$this->startSetup();

$this->run("
    ALTER TABLE `{$this->getTable('tandem_oenologistuser_oenologist')}` ADD `customer_id`  VARCHAR(255);
    ALTER TABLE `{$this->getTable('tandem_oenologistuser_oenologist')}` ADD `instagramtoken` TEXT;
    ALTER TABLE `{$this->getTable('tandem_oenologistuser_oenologist')}` ADD `facebooktoken`  TEXT;
    ALTER TABLE `{$this->getTable('tandem_oenologistuser_oenologist')}` ADD `twittertoken`  TEXT;
"); 

$this->endSetup();
10
  • It will also worked if I use this module with some other magento installation. I mean it will create complete table? Sep 15, 2016 at 9:01
  • yes this is work for other magento as well. Sep 15, 2016 at 9:01
  • How I can select data from a table according to any column. Please help. like if I need to select data according to customer Id from my custom table. Table structure is (id, name, customer_id, instagram_token) Sep 15, 2016 at 11:13
  • I have tried this: $oenologist = Mage::getModel('tandem_oenologistuser/oenologist'); $oenologist->load($customer_id); $oenologist->setInstagramtoken($token); $oenologist->save(); But not working. I am new to magento Sep 15, 2016 at 11:17
  • The solution you given above not working when I again want to modify my table. Do you have any idea why its not working. This time my version is 0.0.3 sql upgrade script name mysql4-upgrade-0.0.2-0.0.3.php version number updated in config.xml but still new columns not added and no error show Sep 30, 2016 at 11:55
0

I would try to stick with the table name I used in the installation script, especially if I had table prefixes.

You used getTable('tandem_oenologistuser_oenologist') in the installation script, but you use getTable('tandem_oenologistuser/oenologist') in the upgrade script.

2
  • I have also tried this getTable('tandem_oenologistuser/oenologist') in upgrade script also but it's not working @Rahesh answer worked for me. Thanks for the comment Sep 15, 2016 at 8:59
  • I'm saying the the exact opposite. Try getTable('tandem_oenologistuser_oenologist') instead Sep 15, 2016 at 9:00

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.