2

I have created one install script install-1.0.0.0.1.php that is as below

$installer = $this;

$table = $installer->getConnection()
->newTable($installer->getTable('magentostudy_news/news'))

->addColumn('news_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'unsigned' => true,
    'identity' => true,
    'nullable' => false,
    'primary'  => true,
), 'Entity id')

->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
    'nullable' => true,
), 'Title')

->addColumn('author', Varien_Db_Ddl_Table::TYPE_TEXT, 63, array(
    'nullable' => true,
    'default'  => null,
), 'Author')
->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, '2M', array(
    'nullable' => true,
    'default'  => null,
), 'Content')
->addColumn('image', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
    'nullable' => true,
    'default'  => null,
), 'News image media path')
->addColumn('published_at', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
    'nullable' => true,
    'default'  => null,
), 'World publish date')
->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
    'nullable' => true,
    'default'  => null,
), 'Creation Time')
->addIndex($installer->getIdxName(
        $installer->getTable('magentostudy_news/news'),
        array('published_at'),
        Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX
    ),
    array('published_at'),
    array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX)
)
->setComment('News item');

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

and here is my upgrade script mysql4-upgrade-1.0.0.0.1-1.0.0.0.2.php for alter existing table to linking product with my table

  $installer = $this;

  $table = $installer->getConnection()

->addColumn($installer->getTable('magentostudy_news/news'),'product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'unsigned'  => true,
    'nullable'  => false,
    'default'   => '0',
), 'Product ID')

->addColumn($installer->getTable('magentostudy_news/news'),'position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    'default'   => '0',
), 'Position')

->addIndex($this->getIdxName('magentostudy_news/news', array('product_id')), array('product_id'))

->addForeignKey($this->getFkName('magentostudy_news/news', 'news_id', 'magentostudy_news/news', 'entity_id'), 'news_id', $this->getTable('magentostudy_news/news'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)

->addForeignKey($this->getFkName('magentostudy_news/news', 'product_id', 'catalog/product', 'entity_id'),    'product_id', $this->getTable('catalog/product'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->setComment('News to Product Linkage Table');

When i run my URL its simply displaying blank page with no error messages There is some problem with upgrade script syntax only as install script working fine and when i remove upgrade script whole site working fine...plz help

2
  • try to activate the developer mode to see some error messages :) Commented Sep 17, 2014 at 15:54
  • I have enabled the developer mode and its showing this error in upgrade script file... Fatal error: Call to a member function addColumn() on a non-object on line 22 that is in addColumn() method.. Commented Sep 18, 2014 at 5:51

1 Answer 1

9

I just had this problem. For me, the solution was to unchain the addColumn calls in your upgrade script. Like this:

$installer->getConnection()
    ->addColumn($installer->getTable('magentostudy_news/news'),'product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'unsigned'  => true,
        'nullable'  => false,
        'default'   => '0',
    ), 'Product ID');

$installer->getConnection()
    ->addColumn($installer->getTable('magentostudy_news/news'),'position', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'nullable'  => false,
        'default'   => '0',
    ), 'Position');

The addColumn in this case returns the query results rather than the connection so they cannot be chained.

Try deleting your tables and simplifying your upgrade script. Add one field at a time so you can find out which column is causing the error.

Also, the error should be somewhere. Make sure you enable logging in the admin and check the exception.log.

1
  • thx. 2019, m2.3, still actual. Commented Mar 16, 2019 at 11:55

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.