I've InstallSchema
that created one table that's worked fine, but later on somehow scope changed and now need to change one specific column's datatype
.
I tried with UpgradeSchema
but doesn't seems to work.
Any idea to implement this ?
I know I can change via deleting existing table but I'm working on git setup so....
app/code/Vendor/Module/etc/module.xml:
<module name="Vendor_Module" setup_version="1.0.4" schema_version="1.0.4"/>
app/code/Vendor/Module/Setup/UpgradeSchema.php:
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* {@inheritdoc}
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
if (version_compare($context->getVersion(), '1.0.4') < 0) {
$connection = $setup->getConnection();
$connection->addColumn(
$setup->getTable('one_table'),
'serial_number',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'default' => '',
'comment' => 'Serial Number'
]
);
}
}
}
app/code/Vendor/Module/Setup/InstallSchema.php:.
->addColumn(
'serial_number',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
255,
['nullable => false'],
'Serial Number'
)