Not Null Contraint Rails

Viewed 33

I have a specific requirement, one column cannot be set as null once some value is added.

On create its value is set as null by default Once the value is added to the column, it cannot be empty.

For such a case I am trying to add check_constraints

add_check_constraint :user, 'registery_id != null', name: 'reg_id

This constraint is added on both insert and update calls.

Rail Version 7 Ruby 3.x

I want it only to be executed in the case of an update only.

0 Answers
Related