When I wanted to change the column name when creating a flea market app at a certain programming school, I needed to roll back the migration file, so I will write what I checked at that time.
First run the following in the terminal
$ rails db:rollback
$ rails db:migrate:status
↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200510074001  Create spending categories
   up     20200510074005  Create income categories
   up     20200510074056  Create incomes
  down    20200510074140  Create spendings
You can send back multiple files by specifying the number with STEP = at the end as shown below. This time, I will send back all four.
$ rails db:rollback STEP=4 
  
$ rails db:migrate:status
↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
  down    20200510074001  Create spending categories
  down    20200510074005  Create income categories
  down    20200510074056  Create incomes
  down    20200510074140  Create spendings
If you specify "Migration ID" in VERSION as shown below, you can return only the selected migration file.
$ rails db:migrate:down VERSION=20200510074001 
$ rails db:migrate:status
↓ I think it will be displayed in the terminal like this
 Status   Migration ID    Migration Name
--------------------------------------------------
  down    20200510074001  Create spending categories
   up     20200510074005  Create income categories
   up     20200510074056  Create incomes
   up     20200510074140  Create spendings
Thank you for watching till the end! !!
I hope you found this article helpful: pray_tone2:
Recommended Posts