I wrongly named a column hased_password instead of hashed_password.
How do I update the database schema, using migration to rename this column?
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.
You’ll probably want to create a separate migration to do this. (Rename
FixColumnNameas you will.):Then edit the migration to do your will:
For Rails 3.1 use:
While, the
upanddownmethods still apply, Rails 3.1 receives achangemethod that "knows how to migrate your database and reverse it when the migration is rolled back without the need to write a separate down method".See "Active Record Migrations" for more information.
If you happen to have a whole bunch of columns to rename, or something that would have required repeating the table name over and over again:
You could use
change_tableto keep things a little neater:Then just
db:migrateas usual or however you go about your business.For Rails 4:
While creating a
Migrationfor renaming a column, Rails 4 generates achangemethod instead ofupanddownas mentioned in the above section. The generatedchangemethod is:which will create a migration file similar to: