Skip to content

Instantly share code, notes, and snippets.

@philsof
Last active February 11, 2016 20:53
Show Gist options
  • Save philsof/ab73b76152cab8bf6e4f to your computer and use it in GitHub Desktop.
Save philsof/ab73b76152cab8bf6e4f to your computer and use it in GitHub Desktop.
How to implement a unique constrait in an Active Record migration

Here are the docs and here is a highly rated StackOverflow answer. (The docs are pretty long, you will probably want to search the web page for "unique" to find the relevant info.)

Bottom line: You need to create an index and make the index unique:

add_index :table_name, :column_name, :unique => true

Hope this helps. Any questions let me know.

-Phil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment