3

I have created a lot of tables using InstallSchema.php and put some data by InstallData.php in my custom module.

Once i want create a new table, Can i do it with upgrade scripts so i'm not create it manually in phpmyadmin? If using install schema i had to remove my module in setup_module table, and it makes data is reinserted while doing setup upgrade.

6

Yes, we can create new table using UpgradeSchema.php. Inside public function upgrade() add below scripts:

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

    $table = $installer->getConnection()
        ->newTable($installer->getTable('custom_table'))
        ->addColumn(/* put some column attribute here */);

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

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.