0
<?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.

2

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.

  • still not working. See my updated code – Arshad Hussain Jul 9 at 5:11
  • what's the error now? – Mohit Rane Jul 9 at 5:13
  • 1
    It is working Mohit. Thanks mate. I forgot to apply same code most below. – Arshad Hussain Jul 9 at 5:16
  • glad i could help. – Mohit Rane Jul 9 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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