[RUBY] Rails "How to delete NO FILE migration files"

Status

I deleted the migration file after executing $ rails db: migrate, and a NO FILE file was created.

Solution

1. Check the status of migrate.

Terminal


rails db:migrate:status

Then it will be displayed like this ↓

Terminal


 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200602094458  Create messages
   up     20200604080747  ********** NO FILE **********
2. Copy and paste the Migration ID of NO FILE to create a dummy file. (Hoge is optional)

Terminal


touch db/migrate/20200604080747_hoge.rb
3. Create the contents of the dummy file.

20200604080747_hoge.rb



class Hoge < ActiveRecord::Migration[5.2]
  def change
  end
end
4, Confirm that the Migration Name is given.

Terminal


rails db:migrate:status

Then it will be displayed like this ↓

Terminal


 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200602094458  Create messages
   up     20200604080747  Hoge
5. Set the Status of the migration file you want to delete down. ($ rails db migrate, restore before execution)

Terminal


rails db:migrate:down VERSION=20200604080747

Check if it is down

Terminal


rails db:migrate:status

Terminal


 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200602094458  Create messages
  down    20200604080747  Hoge
6, delete after confirming down
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200602094458  Create messages

Be careful when handling migration files. It's a considerable loss of time.

Recommended Posts

Rails "How to delete NO FILE migration files"
How to delete the migration file NO FILE
[Beginner] How to delete NO FILE
How to delete the wrong migration file
[Rails] Delete the migration file
How to rollback migration files
[Rails] About migration files
How to write Rails
How to uninstall Rails
What to do when you want to delete a migration file that is "NO FILE"
How to delete a new_record object built with Rails
Completely delete the migration file that you failed to delete
How to delete BOM (UTF-8)
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
[rails] Deleted NOFILE migration file
How to use rails join
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
How to write a migration from Rails datetime type to date type
[Rails] How to delete images uploaded by carrierwave (using devise)
[Rails5] japanMap link How to write parameters in js.erb file
[Rails] How to install Font Awesome
[Rails] How to use devise (Note)
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
How to disassemble Java class files
[Rails] Various ways to delete data
How to use Ruby on Rails
How to deploy Bootstrap on Rails
How to convert erb file to haml
[Rails] How to speed up docker-compose
[Rails] How to add new pages
How to decompile java class files
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
How to add the delete function
[Introduction to Rails] How to use render
How to install Swiper in Rails
How to make a jar file with no dependencies in Maven
How to delete large amounts of data in Rails and concerns