Zend certified PHP/Magento developer

Magento 2: How to allow updating a null value for a column having foreign key constraint?

I have 2 tables A and B

A

  • id
  • name

B

  • id
  • name
  • a_id FK references A(id)

I used the Magento’s upgrade script to add both tables, everything was created correctly, however when i tried to setting a_id to null via Magento code it throws a FK exception:

Something went wrong while saving the B.SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

However when i tried updating the column via MySQL directly i have no problems:

UPDATE B SET a_id = null WHERE id = 1;

So it is Magento’s MagentoFrameworkForeignKeyStrategyRestrict that is not allowing this operation. How can i avoid this restriction then since MySQL didn’t throw any errors.