How to add new table in existing module using UpgradeSchema in Magento 2





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















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.










share|improve this question





























    3















    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.










    share|improve this question

























      3












      3








      3








      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.










      share|improve this question














      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.







      magento2 database upgradeschema






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 13 '18 at 22:34









      i_ali55i_ali55

      419112




      419112






















          2 Answers
          2






          active

          oldest

          votes


















          3














          i have got the correct working answer.



          <?php

          namespace VendorModuleSetup;

          use MagentoFrameworkSetupUpgradeSchemaInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkDBDdlTable;


          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" .






          share|improve this answer
























          • 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' )

            – i_ali55
            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.

            – i_ali55
            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' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          'nullable' => true,
          'comment' => 'Author ID',

          ]
          );

          }
          }





          share|improve this answer


























          • kindly mention the issue as well.

            – i_ali55
            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.

            – i_ali55
            Aug 13 '18 at 22:53












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f238251%2fhow-to-add-new-table-in-existing-module-using-upgradeschema-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          i have got the correct working answer.



          <?php

          namespace VendorModuleSetup;

          use MagentoFrameworkSetupUpgradeSchemaInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkDBDdlTable;


          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" .






          share|improve this answer
























          • 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' )

            – i_ali55
            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.

            – i_ali55
            Jan 25 at 16:34
















          3














          i have got the correct working answer.



          <?php

          namespace VendorModuleSetup;

          use MagentoFrameworkSetupUpgradeSchemaInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkDBDdlTable;


          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" .






          share|improve this answer
























          • 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' )

            – i_ali55
            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.

            – i_ali55
            Jan 25 at 16:34














          3












          3








          3







          i have got the correct working answer.



          <?php

          namespace VendorModuleSetup;

          use MagentoFrameworkSetupUpgradeSchemaInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkDBDdlTable;


          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" .






          share|improve this answer













          i have got the correct working answer.



          <?php

          namespace VendorModuleSetup;

          use MagentoFrameworkSetupUpgradeSchemaInterface;
          use MagentoFrameworkSetupSchemaSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoFrameworkDBDdlTable;


          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" .







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 16 '18 at 23:28









          i_ali55i_ali55

          419112




          419112













          • 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' )

            – i_ali55
            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.

            – i_ali55
            Jan 25 at 16:34



















          • 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' )

            – i_ali55
            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.

            – i_ali55
            Jan 25 at 16:34

















          should change to whaetever we are using here? $context->getVersion(), '2.0.2'

          – jafar pinjar
          Jan 24 at 13:57





          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





          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' )

          – i_ali55
          Jan 24 at 17:32





          @jafarpinjar ->addColumn( 'voting_id', Table::TYPE_SMALLINT, 11, ['nullable' => true, 'primary' => true, 'auto_increment' => true], 'Voting ID' )

          – i_ali55
          Jan 24 at 17:32













          I am getting base table not found error

          – jafar pinjar
          Jan 25 at 2:51





          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.

          – i_ali55
          Jan 25 at 16:34





          if you please post your code then i can understand what actually problem is.

          – i_ali55
          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' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          'nullable' => true,
          'comment' => 'Author ID',

          ]
          );

          }
          }





          share|improve this answer


























          • kindly mention the issue as well.

            – i_ali55
            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.

            – i_ali55
            Aug 13 '18 at 22:53
















          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' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          'nullable' => true,
          'comment' => 'Author ID',

          ]
          );

          }
          }





          share|improve this answer


























          • kindly mention the issue as well.

            – i_ali55
            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.

            – i_ali55
            Aug 13 '18 at 22:53














          2












          2








          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' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          'nullable' => true,
          'comment' => 'Author ID',

          ]
          );

          }
          }





          share|improve this answer















          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' => MagentoFrameworkDBDdlTable::TYPE_INTEGER,
          'nullable' => true,
          'comment' => 'Author ID',

          ]
          );

          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 min ago









          Hassan Al-Jeshi

          21428




          21428










          answered Aug 13 '18 at 22:43









          sheraz khansheraz khan

          17311




          17311













          • kindly mention the issue as well.

            – i_ali55
            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.

            – i_ali55
            Aug 13 '18 at 22:53



















          • kindly mention the issue as well.

            – i_ali55
            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.

            – i_ali55
            Aug 13 '18 at 22:53

















          kindly mention the issue as well.

          – i_ali55
          Aug 13 '18 at 22:46





          kindly mention the issue as well.

          – i_ali55
          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







          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





          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.

          – i_ali55
          Aug 13 '18 at 22:53





          your answer is not working for me.

          – i_ali55
          Aug 13 '18 at 22:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f238251%2fhow-to-add-new-table-in-existing-module-using-upgradeschema-in-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What other Star Trek series did the main TNG cast show up in?

          Berlina muro

          Berlina aerponto