4
class UpgradeSchema implements  UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface     $setup,ModuleContextInterface     $context){
$setup->startSetup();
            if (version_compare($context->getVersion(), '2.0.0', '<=')) {
            $installer = $setup;
            $installer->startSetup();

         $table = $installer->getConnection()
        ->newTable($installer->getTable('my_booster'))
        ->addColumn(
            'review_id',
            Table::TYPE_SMALLINT,
            null,
            ['identity' => true, 'nullable' => false, 'primary' => true],
            'Review ID'
        )
        ->addColumn('pros', Table::TYPE_TEXT, 255, ['nullable' => false], 'What I like about this product')
        ->addColumn('cons', Table::TYPE_TEXT, 255, ['nullable' => false], 'What I dislike about this product')
        ->addColumn('title', Table::TYPE_TEXT, 255, ['nullable' => false], 'Custom Title')
        ->addColumn('review_comments', Table::TYPE_TEXT, 255, ['nullable' => false], 'Custom  Comments')
        ->addColumn('send_to', Table::TYPE_TEXT, 255, ['nullable' => false], 'Send reply to Customer')
        ->addColumn('helpful', Table::TYPE_TEXT, 255, ['nullable' => false], 'Was this review helpful?')
        ->addColumn('product_quality', Table::TYPE_TEXT, 255, ['nullable' => false], 'Product Quality ')
        ->addColumn('Product Value', Table::TYPE_TEXT, 255, ['nullable' => false], 'Product Value')
        ->addColumn('product_price', Table::TYPE_TEXT, 255, ['nullable' => false], 'Product Price')
        ->addColumn('image', Table::TYPE_TEXT, 255, ['nullable' => false], 'Viemo');

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

}

I am using this script.

4

i have got the correct working answer.

<?php

namespace Vendor\Module\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\DB\Ddl\Table;


class UpgradeSchema implements  UpgradeSchemaInterface
{
  public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    $setup->startSetup();

    if (version_compare($context->getVersion(), '2.0.2', '<')) {
      $setup->getConnection()->addColumn(
        $setup->getTable("enter table name here"),
        'enter new column name here',
        [
          "type" => Table::TYPE_TEXT,
          "nullable" => true,
          "comment" => "xample"
        ]
      );
      $setup->getConnection()->addColumn(
        $setup->getTable("enter table name here"),
        'enter new second column name here',
        [
          "type" => Table::TYPE_TEXT,
          "nullable" => true,
          "comment" => "Xample 2"
        ]
      );
      $setup->getConnection()->addColumn(
        $setup->getTable("enter table name here"),
        'enter new third column name here',
        [
          "type" => Table::TYPE_TEXT,
          "nullable" => true,
          "comment" => "Xample 3"
        ]
      );

    }
    $setup->endSetup();
}
}

also you need to change etc/module.xml file. where setup_version="2.0.1" schema_version="2.0.1" .

  • should change to whaetever we are using here? $context->getVersion(), '2.0.2' – jafar pinjar Jan 24 at 13:57
  • how to create primary key with integer? – jafar pinjar Jan 24 at 15:24
  • @jafarpinjar ->addColumn( 'voting_id', Table::TYPE_SMALLINT, 11, ['nullable' => true, 'primary' => true, 'auto_increment' => true], 'Voting ID' ) – sudo55 Jan 24 at 17:32
  • I am getting base table not found error – jafar pinjar Jan 25 at 2:51
  • if you please post your code then i can understand what actually problem is. – sudo55 Jan 25 at 16:34
2

Try this

class UpgradeSchema implements UpgradeSchemaInterface
{

    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $setup->startSetup();

        $version = $context->getVersion();
        $connection = $setup->getConnection();

        if (version_compare($version, '2.0.0') < 0) {
            $connection->addColumn(
                $setup->getTable('my_booster'),
                'author_id',
                [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    'nullable' => true,
                    'comment' => 'Author ID',

                ]
            );

        }
    }
  • kindly mention the issue as well. – sudo55 Aug 13 '18 at 22:46
  • here is the issue if (version_compare($context->getVersion(), '2.0.0', '<=')) , withi which you are comparing – sheraz khan Aug 13 '18 at 22:48
  • try this if (version_compare($version, '2.0.0') < 0) – sheraz khan Aug 13 '18 at 22:49
  • your answer is not working for me. – sudo55 Aug 13 '18 at 22:53

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.