Error on creating UpgradeSchema.php
-
06-03-2021 - |
Question
<?php
namespace Essence\Slider\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface {
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
){
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '1.1.0', '<')){
if(!$installer->tableExists('bt_essence_slider')) {
$table = $installer->getConnection()->newTable(
$installer->getTable('bt_essence_slider')
)
->addColumn(
'id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
[
'identity' => true,
'nullable' => false,
'primary' => true,
'unsigned' => true
],
'Banner ID'
)
->addColumn(
'banner_name',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
[
'nullable' => false
],
'Banner Name'
)
->addColumn(
'status',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
[
'nullable' => false,
'default' => '1'
],
'Banner Status: Enabled is: 1, Disabled is: 2'
)
->addColumn(
'created_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
[
'nullable' => false,
'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT,
],
'Created At'
)
->addColumn(
'updated_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
[
'nullable' => false,
'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE,
],
'Updated At'
)
->setComment('Slider Table');
$installer->getConnection->createTable($table);
}
}
$installer->endSetup();
}
}
And when I try to run following command:
php bin magento setup:upgrade
I am getting following error in command line:
Undefined property: Magento\Setup\Module\Setup::$getConnection in UpgradeSchema.php on line 18
I cannot find out what is the problem here. Please help.
Solution
getConnection()
is function you forgot to mention as function
Your code should be like this
$table = $setup->getConnection()->newTable(
$setup->getTable('bt_essence_slider')
Hope it helps.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange