Add varchar column to order address
-
16-10-2019 - |
Question
I am trying to add a few varchar fields to the sales/order_address table but am coming up against a column definition error.
I have the following code:
$oInstaller->getConnection()
->addColumn(
$oInstaller->getTable('sales/order_address'),
'address_email',
array(
'nullable' => false,
'length' => 255,
'type' => Varien_Db_Ddl_Table::TYPE_VARCHAR,
'comment' => 'Company Email Address'
)
);
This returns the error: [message:protected] => Invalid column definition data
If I change the code to use Varien_Db_Ddl_Table::TYPE_INTEGER
then the code runs and the column is added. I have tried removing the length and nullable attributes but to no avail.
EDIT
When updating the script is updated as follows then it works. Does anyone know what causes this error?
$oInstaller->getConnection()
->addColumn(
$oInstaller->getTable('sales/order_address'),
'address_email',
Varien_Db_Ddl_Table::TYPE_VARCHAR . '(255)'
);
Solution
Use TYPE_TEXT
. TYPE_VARCHAR
is deprecated (@see Varien_Db_Adapter_Pdo_Mysql::$_ddlColumnTypes
)
And don't worry about the storage space. If you specify type TYPE_TEXT
but set length
to lets say 255
Magento will create a MySQL column of VARCHAR
type.