I’d like to add a column to a table using a migration. Is there a way to add it in a particular position, rather than as the last column? I could find any “order” option in the API docs.
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.
I don’t believe that it is possible to do this with migrations “natively”. The reason for this is that many databases do not support the addition of columns at arbitrary locations. The hoops you need to go through to do this with databases that do not support it are non trivial.
If your DB does support it and you do not wish to support multiple databases then you can use an execute statement directly within your migration.