-1

Let's say I created User model with email:string password_digest:string.

Later on I decided to add another column type:string.

Can I just edit migration file and run rake task again to update database?

Also, I know there is command rake db:rollback, but can I specify which migration I want to rollback?

Joe Half Face
  • 2,303
  • 1
  • 17
  • 45

1 Answers1

1

Generally, the easiest thing is to just add a new migration to add your new column.

However, if your migration hasn't been run yet, you can certainly edit it, and then run it.

Also, if you have already run the migration, you can do a rake db:rollback, and then edit your migration, and then run it again. (I would only do this if the migration has only run in development mode and hasn't been pushed to production.)

In terms of specifying which migration you want to roll back, migrations are applied, and also rolled back, in chronological order. If you want to rollback the 3rd last migration you did, then you have to roll back the last one you did, then the second last one, then the 3rd last one. So, in that sense, you can't specify a specific migration to rollback. You have to specify a migration to "roll back to" - ie, roll back all migrations that happened since that migration.

joshua.paling
  • 13,762
  • 4
  • 45
  • 60