12

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)'
    );
49

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.

  • 2
    works ! ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array( 'nullable' => true, 'length' => 255, ), null) – Martijn van Hoof Mar 25 '15 at 13:13
  • I'm surprised that it was this simple... The class says it would internally convert the deprecated types to non-deprecated, but I suppose that's for pre-existing values? Either way, plus one – Robbie Averill Apr 20 '15 at 1:54

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.