Add a column after another one in Magento 2
<?php | |
namespace My\Module\Setup; | |
use Magento\Framework\Setup\ModuleContextInterface; | |
use Magento\Framework\Setup\SchemaSetupInterface; | |
use Magento\Framework\Setup\UpgradeSchemaInterface; | |
/** | |
* @codeCoverageIgnore | |
*/ | |
class UpgradeSchema implements UpgradeSchemaInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) | |
{ | |
$setup->startSetup(); | |
if (version_compare($context->getVersion(), '[SOME_VERSION]', '<')) { | |
$setup->getConnection()->addColumn( | |
$setup->getTable('my_module_table'), | |
'my_column_name', | |
[ | |
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, // Or any other type | |
'nullable' => true, // Or false | |
'comment' => 'Some comment', | |
'after' => 'some_column_to_place_the_new_one_after' | |
] | |
); | |
} | |
$setup->endSetup(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment