models/user.rb
validates :email, uniqueness: true
$ rails g migration add_column_to_users
add_column_to_users.rb
def change
add_index :users, :email, unique: true
end
$ rails db:migrate
** Indexing ** is also required to make the columns of the table unique. The reason is that by searching all the data, you can check if it is duplicated with the past data.
Recommended Posts