2

I want to add new decimal column in sales_order_item table, I got this error when i run upgrade:setup command run. https://www.screencast.com/t/yGFPIhPJz

Is this below code correct? Please help me

$tableName = $setup->getTable('sales_order_item');
            if ($setup->getConnection()->isTableExists($tableName) == true) {
                $columns = [
                    'extra_weight' => [
                        'type'      => [\Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, '10,2'],
                        'nullable'  => true,
                        'default'   => 0.00,
                        'comment'   => 'Item extra Weight'
                    ]
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($tableName, $name, $definition);
                }
            }
4

Please change type parameter and add length parameter

$tableName = $setup->getTable('sales_order_item');
            if ($setup->getConnection()->isTableExists($tableName) == true) {
                $columns = [
                    'extra_weight' => [
                        'type'      => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
                        'length'    => '10,2',
                        'nullable'  => true,
                        'default'   => 0.00,
                        'comment'   => 'Item extra Weight'
                    ]
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($tableName, $name, $definition);
                }
            }

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.