[RAILS] How to delete the wrong migration file

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.

First, check the migration status

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.

Delete migration!

rm -rf db/migrate/20201223095940_add_devise_to_users.rb

Then run rails db: migrate and run rails db: migrate: status again.

Cleanly deleted

 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.

Summary

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!

reference

-[Rails] Delete migration file

Recommended Posts

How to delete the wrong migration file
How to delete the migration file NO FILE
Rails "How to delete NO FILE migration files"
[Rails] Delete the migration file
Completely delete the migration file that you failed to delete
[Beginner] How to delete NO FILE
How to add the delete function
[Java] How to use the File class
[For beginners] How to implement the delete function
How to delete the database when recreating the application
[Spring Boot] How to refer to the property file
How to delete BOM (UTF-8)
The migration file is duplicated
How to delete / update the list field of OneToMany
[Java] How to extract the file name from the path
How to debug the generated jar file in Eclipse
How to rollback migration files
Solution if you delete the migration file in the up state
How to correctly check the local HTML file in the browser
How to change the contents of the jar file without decompressing
How to change the file name with Xcode (Refactor Rename)
How to use the link_to method
Add Extended Attributes to the file
How to use the include? method
How to use the form_with method
How to find the average angle
How to use the wrapper class
How to convert erb file to haml
How to create a jar file or war file using the jar command
[chown] How to change the owner of a file or directory
How to get the length of an audio file in java
[Xcode] How to add a README.md file
Migration file to add comment to Rails table
[Java] How to use the hasNext function
How to put out the error bundling
[Java] How to use the HashMap class
[Rails] How to use the map method
How to add jar file in ScalaIDE
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to determine the number of parallels
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
[Swift] How to implement the countdown function
How to change the timezone on Ubuntu
How to achieve file download with Feign
Ransack sort_link How to change the color!
[Processing × Java] How to use the class
How to sort the List of SelectItem
How to install the legacy version [Java]
How to find the tens and ones
How to pass the value to another screen
How to get the date in java
Try changing the .erb file to .slim
[Processing × Java] How to use the function
How to delete data with foreign key
[Java] How to use the Calendar class
Summarized how to climb the programming stairs
How to split Spring Boot message file
How to achieve file upload with Feign