I want to specify a unique index on a column, but I also need to allow NULL values (multiple records can have NULL values). When testing with PostgreSQ
NULL
Your migration will work and will allow multiple null values (for the most database engines).
null
But your validation for the user class should look like below.
validates :email, uniqueness: true, allow_nil: true