[RUBY] [Rails] Delete the migration file

Reference target person

--Those who want to know how to operate the migration file

environment

$ rails -v
Rails 6.0.3.1
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.29, for osx10.15 (x86_64) using  EditLine wrapper

Delete the migration file

Suppose you want to delete the file Add column to users

--Check the migration ID of the file you want to delete

$ rails db:migrate:status

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200618162841  Create tweetposts
   up     20200620004226  Change tweetposts to tweets
  down    20200621075518  Create posts
  down    20200623102444  Change posts to chats
  down    20200627042358  Create users
   up     20200627080839  Create users
   up     20200627083356  Add column to users
  down    20200627220915  Change datatype content of chats
  down    20200710035709  Add user id to tweets

--Specify ID and bring down

$ rails db:migrate:down VERSION=Add column to users

--Move the downed file to the trash

$ rm db/migrate/20200703201452_add_column_to_users.rb

When the migration file is deleted before going down

********** no file **********I want to delete the file in the up state with the file

--Check the migration ID of the file you want to delete

$ rails db:migrate:status

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200618162841  Create tweetposts
   up     20200620004226  Change tweetposts to tweets
  down    20200621075518  Create posts
  down    20200623102444  Change posts to chats
  down    20200627042358  Create users
   up     20200627080839  Create users
   up     20200627083356  Add column to users
  down    20200627220915  Change datatype content of chats
   up     20200703201452  ********** NO FILE **********
  down    20200710035709  Add user id to tweets

--Create a file with the same name as the deleted migration file name

$ touch db/migrate/20200703201452_add_column_to_users.rb

20200703201452_add_column_to_users.rb


class AddColumnToUsers < ActiveRecord::Migration
  def change
  end
end
$ rails db:migrate:down VERSION=20200703201452
$ rm db/migrate/20200703201452_add_column_to_users.rb

Recommended Posts

[Rails] Delete the migration file
How to delete the wrong migration file
Rails "How to delete NO FILE migration files"
The migration file is duplicated
[rails] Deleted NOFILE migration file
Rails migration
Completely delete the migration file that you failed to delete
Check the migration status of rails
Solution if you delete the migration file in the up state
Migration file to add comment to Rails table
Read the Rails Guide (Active Record Migration) again
[Rails] About migration files
[Rails] Migration command summary
Various rails migration operations
Understand migration in rails
Master the [Rails] scope!
about the where method (rails)
Delete all the contents of the list page [Ruby on Rails]
Rails ~ Understanding the message function ~
Cancel Ruby on Rails migration
[PostgreSQL] If you want to delete the Rails app, delete the database first!
[Rails] What was the error message?
Add Extended Attributes to the file
Database command for migration file environment
[Java] Delete the elements of List
[Rails] About the Punk List function
[Rails] Check the contents of the object
Replace the contents of the Jar file
About the symbol <%%> in Rails erb
Minimal Rails with reduced file generation
Unzip the zip file in Java
[Rails] I tried deleting the application
[Beginner] How to delete NO FILE
[Rails 6] destroy using the resources method
How to add the delete function
[Rails] Modify migrate file (rails db: rollback)
Check the root on the Rails browser
[Rails] I learned about migration files! (Adding a column to the table)
[Rails] Check the instance variables and local variables of the file you are browsing