[Beginner] How to delete NO FILE

I made a mistake in the migration file, deleted it manually in a hurry, and then rails db: migrate resulted in an error. At that time, NO FILE came out.

How to delete

① Check the migration file Check the current status and check the ID of the migration file with $ rails db: migration: status.

$ rails db:migration:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200518132414  Devise create users
   up     20200521083405  Add name to users
   up     20200525013751  Create posts
   up     20200527010431  Add picture to posts
   up     20200528232616  ********** NO FILE **********
   up     20200531083300  Create comments

Confirm that the ID that is NO FILE is 20200528232616

② Create a dummy file Any part of hoge is okay because the file will be deleted later.

touch db/migrate/20200528232616_hoge.rb

20200528232616_hoge.rb


 class Hoge < ActiveRecord::Migrattion[5.3] #5.Match part 3 to the version of rails
   def change
   end
 end

③ Delete the migration file

Check the current situation

$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200518132414  Devise create users
   up     20200521083405  Add name to users
   up     20200525013751  Create posts
   up     20200527010431  Add picture to posts
   up     20200528232616  Hoge 
   up     20200531083300  Create comments

At present, the Migration Name is properly attached like this. From here, change the migration file from up to down.

$ rails db:migration:down VERSION=2020052823261
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200518132414  Devise create users
   up     20200521083405  Add name to users
   up     20200525013751  Create posts
   up     20200527010431  Add picture to posts
  down    20200528232616  Hoge 
   up     20200531083300  Create comments

After confirming that it is in the down state, delete it.

$ rm db/migrate/db/migrate/20200528232616_hoge.rb

When I check it again,

$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200518132414  Devise create users
   up     20200521083405  Add name to users
   up     20200525013751  Create posts
   up     20200527010431  Add picture to posts
   up     20200531083300  Create comments

It should have disappeared properly! !!

Summary

First of all, even if you make a mistake in the migration file, it is important not to delete it in a hurry in the up state.

Recommended Posts

[Beginner] How to delete NO FILE
Rails "How to delete NO FILE migration files"
How to add the delete function
How to delete data with foreign key
How to split Spring Boot message file
How to achieve file upload with Feign
[Spring Boot] How to refer to the property file
How to use identity
How to debug the generated jar file in Eclipse
[Beginner] How to use devise Change settings from introduction
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper
How to use Gradle
Completely delete the migration file that you failed to delete
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to type backslash \
How to concatenate strings
How to change the contents of the jar file without decompressing
Java --How to make JTable
How to use Java variables
[Rails] How to disable turbolinks
[iOS] How to read Carthage
How to check JSF version
How to handle an instance
[Rails] How to use authenticate_user!
How to convert Java radix
How to use GC Viewer
[Rails] How to implement scraping
[Rails] How to make seed
[Rails] How to install simple_calendar
[Java] How to implement multithreading
[Rails] How to install reCAPTCHA
How to use Lombok now
How to install JDK8-10 (Mac)
How to initialize Java array
How to insert a video
[Rails] Delete the migration file
How to create a method
How to rollback migration files
[Creating] How to use JUnit
[Rails] How to use Scope
How to authorize using graphql-ruby
How to read a file and treat it as standard input
[chown] How to change the owner of a file or directory
How to get the length of an audio file in java
How to realize huge file upload with Rest Template of Spring
[Rails] Delete the migration file
Rails "How to delete NO FILE migration files"
Understand migration in rails
Cancel Ruby on Rails migration
[Rails] Modify migrate file (rails db: rollback)