[Rails] Modify migrate file (rails db: rollback)

Hello, this is tt_tsutsumi. This time, I will explain how to change the migrate file. I hope this article helps somebody.

When changing or adding columns while creating an application I was confused because it made a difference from how to write ordinary code. I will describe the process and flow that I performed at that time.

  1. rails db:migrate:status

First, let's check the operating status of migrate of the application you are currently creating. Enter the code below at the console.

$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     year/month/day  Devise create users
   up     year/month/day  Create spots

If the status part is up in the above, the migrate file is running. Even if you change or add the migrate file at this time, it will not be reflected.

  1. rails db:rollback

The operating status of the migrate file is down.

$ rails db:rollback
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     year/month/day  Devise create users
   down   year/month/day  Create spots

The important thing here is ** rails db: rollback ** !! You can bring down the running migate file by hitting this code.

  1. rails db:migrate

Make sure that it is down, and then change or delete the migrate file. And when the change is finished, save it and do ** rails db: migrate **.

$ rails db:migrate
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     year/month/day  Devise create users
   up     year/month/day  Create spots

This completes modifying and saving the migrate file. Thank you for visiting !!

Recommended Posts

[Rails] Modify migrate file (rails db: rollback)
[Rails] Modify migrate file (rails db: rollback STEP =)
rails db: migrate failed!
Error in rails db: migrate
[heroku] run rails db: migrate doesn't work
After all, what is [rails db: migrate] doing?
[Rails] "private method` String' called ~ "error when db: migrate
[Rails] rails db command summary
About the error that occurred when adding the column name in rails (rails db: migrate, rails db: rollback, add)
PG :: DatatypeMismatch error when doing heroku run rails db: migrate
rails test db only drop
[rails] Deleted NOFILE migration file
Error with db: migrate: reset
[Rails] Delete the migration file
The story that I struggled because I couldn't do "Rails db: migrate".