What’s the preferred syntax for adding an index to a table in Rails via a migration?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The preferred syntax is:
There is a full write up in the docs here. To find the relevant section, just do a ‘Ctrl-F’ (or equivalent on your OS) search for ‘index’. The first result is in the section you want to read over.
You can add in index in a separate migration later on, as shown in this post. Its a bit dated, but the idea is still the same. The most common ‘options’ are
:nameand:unique, for exampleNote: curly brackets are important, as the options are a hash.