When I was working on an online school assignment, I accidentally made an extra migration. Even though it was working well, errors occurred frequently as a result of the migration. panic. I tried to rollback, but I couldn't do it well, so I decided to delete it this time.
Check the current migration status with rails db: migrate: status
.
As a result, it returned like this.
Status Migration ID Migration Name
--------------------------------------------------
up 20201222113451 Devise create users
up 20201223005506 Create items
up 20201223093320 Add nickname to users
down 20201223095940 Add devise to users
The bottom file is the database that has been added. It's down.
rm -rf db/migrate/20201223095940_add_devise_to_users.rb
Then run rails db: migrate
and run rails db: migrate: status
again.
Status Migration ID Migration Name
--------------------------------------------------
up 20201222113451 Devise create users
up 20201223005506 Create items
up 20201223093320 Add nickname to users
The last migration was deleted cleanly, and I was able to confirm the operation safely.
I think the pattern that caused the problem is different from this time, but I wrote a method to solve the migration problem using rollback.
-One case of solving a migration error in Rails
This time I deleted it and tried to deal with it. I still don't understand migration well in my head, but I would like to deepen it little by little. Thank you for the experience of our predecessors!
-[Rails] Delete migration file
Recommended Posts