Chapter 2 · Practice 1 of 4
Make columns NOT NULL unless null has a real meaning
Why it matters
Every nullable column adds a third state your code has to handle, and NULL does not behave like a normal value: NULL = NULL is not true. Most columns should never be empty, so the safe default is to say so.
- Declare columns
NOT NULLand give them a default where it makes sense. - Leave a column nullable only when "unknown" or "not yet" is a real state, such as
deleted_atorshipped_at.