How to delete the migration file NO FILE

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!

Flow to delete

--Creating a dummy file --Give the contents to the created file --Delete dummy file

Solutions

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

How to delete the migration file NO FILE
How to delete the wrong migration file
Rails "How to delete NO FILE migration files"
[Beginner] How to delete NO FILE
[Rails] Delete the migration file
Completely delete the migration file that you failed to delete
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
What to do when you want to delete a migration file that is "NO FILE"
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
How to make a jar file with no dependencies in Maven
[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