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.
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.
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.
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