Wednesday, February 08, 2023

If I specify the default value, do I still need to specify not null?

 Yes, you should still specify null: false if you want to enforce that a column cannot have a NULL value, even if you have specified a default value.

This is because the default value is used as the value for a column when a new record is created and no value is provided for that column. However, if a NULL value is allowed, it's possible to insert a record with a NULL value for that column, which may not be what you want.

By specifying both a default value and null: false, you ensure that every record has a value for that column, and that value is either the default value or a value explicitly provided when the record is created.