[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
How to delete the migration file NO FILE
Rails "How to delete NO FILE migration files"
How to delete the wrong migration file
How to use JUnit (beginner)
How to convert erb file to haml
How to add the delete function
How to make a jar file with no dependencies in Maven
[Xcode] How to add a README.md file
How to add jar file in ScalaIDE
How to achieve file download with Feign
How to delete data with foreign key
How to split Spring Boot message file
How to achieve file upload with Feign
How to deploy
[Ruby] How to convert CSV file to Yaml (Yml)
How to dump from database (DB) to seeds file
How to delete a controller etc. using a command
How to delete the database when recreating the application
How to bind to property file in Spring Boot
[Spring Boot] How to refer to the property file
What to do when you want to delete a migration file that is "NO FILE"
How to develop OpenSPIFe
How to delete / update the list field of OneToMany
How to call AmazonSQSAsync
How to use Map
How to jump from Eclipse Java to a SQL file
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use fields_for
How to use java.util.logging
How to use map
[Java] How to extract the file name from the path
How to deal with No template for interactive request
How to use collection_select
How to adapt Bootstrap
How to delete custom Adapter elements using a custom model
How to use Twitter4J
How to use active_hash! !!
How to install Docker
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to uninstall Rails
How to install docker-machine
[How to use label]
How to delete untagged images in bulk with Docker
How to make shaded-jar
How to use identity
How to use hashes
How to write Mockito
How to download a file (Servlet, HTML, Apache, Tomcat)
How to create docker-compose
How to test file upload screen in Spring + Selenium
How to use JUnit 5
How to convert a file to a byte array in Java
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