How should I define foreign key, index constraints in my db migration script for my Rails app in a 2.3.x environment?
How should I define foreign key, index constraints in my db migration script for
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.
ActiveRecord doesn’t support adding foreign keys in a database-agnostic way, so you’ll need to do this with DB-specific code. Here’s an example for MySQL:
For indexes, you can use
add_index– like so:Edit: Updated answer to clarify that indexes and foreign keys are treated differently.