SQLSTATE[23000]: Integrity constraint violation: 1052 Column ” in where clause is ambiguous in magento2

SQLSTATE[23000]: Integrity constraint violation: 1052 Column ” in where clause is ambiguous in magento2

One of the reason:
In my case I have created same name column filed into sales_order & sales_order_grid in both table.
While filter by custom column i got the following error message.

SQLSTATE[23000]: Integrity constraint violation: 1052 Column ” in where clause is ambiguous, query was:
This issue is because of index or alias is not set for the column field. By default magento system while filter the table it will join above both tables. It will give issue if the both the same are same because alias is not set.

To avoid follow below step, change script

From

$installer->getConnection()->addColumn(
$setup->getTable(‘sales_order’), ‘my_cstom1’, [
‘type’ => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
‘length’ => 20,
‘nullable’ => true,
‘index’ => ‘my_cstom1’,
‘filter_index’ => ‘sales_order.my_cstom1’,
‘comment’ => ‘my_cstom1’
]
);

TO

$installer->getConnection()->addColumn(
$setup->getTable(‘sales_order_grid’), ‘my_cstom1’, [
‘type’ => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
‘length’ => 20,
‘nullable’ => true,
‘index’ => ‘my_cstom1’,
‘comment’ => ‘my_cstom1’
]
);

Leave a Reply