I have a simple MySQL table with one column: name.
I would like to define a unique constraint on this column.
I can do:
class MyModel < ActiveRecord::Base
validates_uniqueness_of :my_column_name
end
but it will work only at the application level, not at the database level.
What would you suggest ?
This is not super-helpful, but it looks like there is not a great answer for enforcing uniqueness at the database level. From the Rails migration guide:
It looks like running the SQL command yourself with the ActiveRecord execute method may be the best way to go if you really want to enforce uniqueness in the database.