It will be first post! I hope you will see it with warm eyes. When any problem is solved in the future, we will actively output it to Qiita.
Let's go!
--Creating a dummy file --Give the contents to the created file --Delete dummy file
First $ rails db: migrate: status
Check the list status of migration files with
Status Migration ID Migration Name
--------------------------------------------------
up 20200730051333 Create aws texts
up 20200730052327 Create movies
up 20200730064626 Devise create users
up 20200804115232 Devise create admin users
up 20200804115235 Create active admin comments
up 20201103112057 Create texts
up 20201106080329 Add genre to movies
up 20201106104436 Add image to texts
up 20201119093844 Create lines
up 20201129113758 ********** NO FILE **********
up 20201205113027 Add text id to read texts
Create a dummy file by copying the 14-digit number [Migration: ID] next to Status [Current: up]
touch db/migrate/20201129113758_hoge.rb
The file name is not specified.
If you check the created file, there is no content, so describe it.
db/migrate/20201129113758_hoge.rb
class Hoge < ActiveRecord::Migration[6.0]
def change
end
end
rails db:migrate:status
Check if the dummy file is reflected in the list of migration files.
Status Migration ID Migration Name
--------------------------------------------------
up 20200730051333 Create aws texts
up 20200730052327 Create movies
up 20200730064626 Devise create users
up 20200804115232 Devise create admin users
up 20200804115235 Create active admin comments
up 20201103112057 Create texts
up 20201106080329 Add genre to movies
up 20201106104436 Add image to texts
up 20201119093844 Create lines
up 20201129113758 Hoge
up 20201205113027 Add text id to read texts
Since it is in the up state, set this to down.
rails db:migate:down VERSION=20201129113758_hoge.rb
Give VERSION the Migration ID and file name. When executed, it will be as follows.
== 20201129113758 Hoge: reverting =============================================
== 20201129113758 Hoge: reverted (0.0000s) ====================================
Check the status again.
Status Migration ID Migration Name
--------------------------------------------------
up 20200730051333 Create aws texts
up 20200730052327 Create movies
up 20200730064626 Devise create users
up 20200804115232 Devise create admin users
up 20200804115235 Create active admin comments
up 20201103112057 Create texts
up 20201106080329 Add genre to movies
up 20201106104436 Add image to texts
up 20201119093844 Create lines
down 20201129113758 Hoge
up 20201205113027 Add text id to read texts
It's down! You can now delete this file.
rm -rf db/migrate/20201129113758_hoge.rb
Check again after execution. ** $ rails db: migrate: status **
Status Migration ID Migration Name
--------------------------------------------------
up 20200730051333 Create aws texts
up 20200730052327 Create movies
up 20200730064626 Devise create users
up 20200804115232 Devise create admin users
up 20200804115235 Create active admin comments
up 20201103112057 Create texts
up 20201106080329 Add genre to movies
up 20201106104436 Add image to texts
up 20201119093844 Create lines
up 20201205113027 Add text id to read texts
It's gone! That's all for the work.
Writing an article is hard, you have to remember Makdown! Lol
Recommended Posts