Magento 2 Add "VARCHAR" type field into custom table
If you are using:
->addColumn(
'your_column',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
55,
['nullable' => false, 'default' => '0'],
'Demo'
)
It will return a column it your dabase a column: your_column
, type varchar(55)
,NOT NULL
, Default 0
If your column has more 255 characters, you need using:
->addColumn(
'your_column',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'2M',
['nullable' => false, 'default' => '0'],
'Demo'
)
Return a column: name your_column
, type mediumtext
,NOT NULL
, Default 0
there is No keyword called "VARCHAR" if you want to create a field with varchar you need use "TEXT" with length if length is not passed then it will consider as text filed
$columns = [
'custom_sku' => [
'type' => Table::TYPE_TEXT,
'nullable' => false,
'LENGTH' =>255,
'comment' => 'custom sku',
],
];
or
->addColumn(
'summary',
Table::TYPE_TEXT,
255,
['nullable' => false, 'default' => '', 'LENGTH' =>255],
'Summary'
)
if it work accept the answer so it will use full for others