Skip to content

Magento 2 update custom column value in sales_order table in a controller file

I have created “custom_column” in “sales_order” table and save the data using event observer.After some actions on that order again I need to change the value of my “custom_column” in a controller file. But When I use this code

$order  = $this->_orderRepository->get($orderId);
$order->setData('custom_column', 'No');
$this->_orderRepository->save($order);

But the value is not saving in to “sales_order” table.
If I use this statement I am getting the ‘custom_column’ value.

$order->getData('custom_column')

What mistake I am doing here ? Can I set the value by using above method ?