0

I am getting this error in UpgradeSchema. I have added one column in these core tables, functionalities are working good. According to coding standard it shows warning message.

 ----------------------------------------------------------------------
     60 | WARNING | Modification of magento database core table
        |         | 'sales_order'
     78 | WARNING | Modification of magento database core table
        |         | 'sales_order_grid'
 ----------------------------------------------------------------------

I have attached my code below

<?php
namespace frontname\modulename\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;

class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $customerGroupTable = $setup->getConnection()->describeTable($setup->getTable('customer_group'));
        $customerGroupIdType = $customerGroupTable['customer_group_id']['DATA_TYPE'] == 'int'
            ? \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER : $customerGroupTable['customer_group_id']['DATA_TYPE'];
        $installer->startSetup();
        if (version_compare($context->getVersion(), '2.0.1') < 0) {
            $eavTable = $installer->getTable('sales_order');
            $columns = [
                'is_wallet_quote' => [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    'nullable' => false,
                    'comment' => 'Is this quote for wallet?',
                ],
                'holded_quote_id' => [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    'nullable' => false,
                    'comment' => 'Holded Quote Id',
                ],

            ];
            $connection = $installer->getConnection();
            foreach ($columns as $name => $definition) {
                $connection->addColumn($eavTable, $name, $definition);
            }
            $eavTable = $installer->getTable('sales_order_grid');
            $columns = [
                'is_wallet_quote' => [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    'nullable' => false,
                    'comment' => 'Is this quote for wallet?',
                ],
            ];
            $connection = $installer->getConnection();
            foreach ($columns as $name => $definition) {
                $connection->addColumn($eavTable, $name, $definition);
            }
        }
        $installer->endSetup();
    }
}

Anyone have any idea about this? Thanks in Advance

2
  • You are missing an important line of code $installer->endSetup(); which should be added right before the function ends update/install function ends.
    – Shireen N
    Feb 7, 2018 at 6:29
  • sorry i forget to add here. now i will change
    – chris
    Feb 7, 2018 at 6:45

1 Answer 1

2

It is not considered a good practice to add or update anything in the structure of Magento.

A better way to do this is to add a new table of your own and add the elements needed as foreign keys if you need anything.

A good explanation is here (However, the explanation was in regards to Magento1, but I think the standard shall remain the same.)

An example to do this can be:-

addForeignKey(
                $installer->getFkName(
                    'yourTable',
                    'yourTable_id',
                    'catalog_product_entity',
                    'entity_id'
                ),
                'entity_id',
                $installer->getTable('catalog_product_entity'),
                'entity_id',
                \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
            ) 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.