Possible to specify unique index with NULLs allowed in Rails/ActiveRecord?

Your migration will work and will allow multiple null values (for the most database engines).

But your validation for the user class should look like below.

validates :email, uniqueness: true, allow_nil: true

Leave a Comment