0
  if (version_compare($context->getVersion(), '1.1.10', '<=')) {
            $installer = $setup;
            $installer->startSetup();

            // Get tutorial_simplenews table
            $tableName = $installer->getTable('blog_post');
            // Check if the table already exists
          if ($installer->getConnection()->isTableExists($tableName) != true) {
            // Create tutorial_simplenews table



            $table = $installer->getConnection()
                ->newTable($tableName)
                ->addColumn(
                    'id',
                    Table::TYPE_INTEGER,                                    
                    [
                        'identity' => true,
                        'unsigned' => true,
                        'nullable' => false,
                        'primary' => true
                    ],
                    'ID'
                )
                ->addColumn(
                    'docid',
                    Table::TYPE_TEXT,   
                    255,                 
                    ['nullable' => false, 'default' => ''],
                    'docid'
                )
                ->addColumn(
                    'order_status',
                    Table::TYPE_TEXT,                    
                    255,
                    ['nullable' => false, 'default' => ''],
                    'Order Status'
                )
                ->addColumn(
                    'order_code',
                    Table::TYPE_TEXT,     
                    255,                                   
                    ['nullable' => false, 'default' => ''],
                    'Order Code'
                )
                  ->addColumn(
                    'order_id',                    
                    Table::TYPE_TEXT,    
                     255,                                    
                    ['nullable' => false, 'default' => ''],
                    'Order Id'
                )
                ->addColumn(
                    'created_at',
                    Table::TYPE_DATETIME,                    
                    ['nullable' => false,'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                    'Created At'
                )
                ->addColumn(
                    'update_at',
                    Table::TYPE_DATETIME,                    
                    ['nullable' => false, 'default' => ''],
                    'Updated At'
                )
                ->setComment('dfdfd')
                ->setOption('type', 'InnoDB')
                ->setOption('charset', 'utf8');
            $installer->getConnection()->createTable($table);           
        }
            $installer->endSetup();


        } 


Warning: array_key_exists() expects parameter 2 to be array, string given i  
  n /var/www/html/readyresale_beta/vendor/magento/framework/DB/Ddl/Table.php   
  on line 352    
0

UpgradeSchema.php

$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.1.10') < 0) {
    // Get module table
    $tableName = $installer->getTable('blog_post');

    // Check if the table already exists
    if ($installer->getConnection()->isTableExists($tableName) == true) {
        // Declare data
        $columns = array(
            'id' => array(
                'type' => Table::TYPE_INTEGER,
                'size' => null,
                'options' => array('nullable' => false, 'default' => ''),
                'comment' => 'Id',
            ),
            'docid' => array(
                'type' => Table::TYPE_INTEGER,
                'size' => null,
                'options' => array('nullable' => true, 'default' => ''),
                'comment' => 'Docid',
            ),
            // Do the same for the other...
        );

        $connection = $installer->getConnection();
        foreach ($columns as $name => $definition) {
            $connection->addColumn($tableName, $name, $definition);
        }
    }
}

Update

To add new table with attributes

$setup->startSetup();
if (version_compare($context->getVersion(), '1.1.10') < 0)) {
    $installer = $setup;
    $installer->startSetup();

    $table = $installer->getConnection()
        ->newTable($installer->getTable('table_name'))
        ->addColumn(
      //...The attributes here (If you have many columns use the foreach solution above)
    );

    $installer->getConnection()->createTable($table);
    $installer->endSetup();
}
  • table is not inserted not showing any error after upgrade script – nick Jul 17 '18 at 15:20
  • Which table ? the table is already exists, here you juste update it to add your new columns – PЯINCƏ Jul 17 '18 at 15:31
  • no i am creating table and colukmn via upgradeschemea.php – nick Jul 18 '18 at 7:22
  • Look my update please – PЯINCƏ Jul 18 '18 at 8:07

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.