0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

マイグレーションファイル NO FILE 削除する方法

Posted at

初投稿になります!暖かい目で見て頂くを幸いです 笑
今後何か問題解決した際には積極的にQiiteにアウトプットします。

それでは行きましょ!

削除する流れ

  • ダミーファイルの作成
  • 作成したファイルに中身与える
  • ダミーファイルの削除

解決方法

まず $ 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     20201129113758  ********** NO FILE **********
   up     20201205113027  Add text id to read texts

Status [現在:up] の横にある 14桁の数字 [Migration:ID] をコピーしダミーファイルを作成

 touch db/migrate/20201129113758_hoge.rb         

ファイル名は特に指定はありません。

作成したファイルを確認すると中身がないので記述する。

db/migrate/20201129113758_hoge.rb
class Hoge < ActiveRecord::Migration[6.0]
  def change
  end
end
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     20201129113758  Hoge
   up     20201205113027  Add text id to read texts

up状態になっているので、こちらをdownにします。

 rails db:migate:down VERSION=20201129113758_hoge.rb

VERSIONにはMigration IDとファイル名を与えます。
実行すると下記のようになります。

== 20201129113758 Hoge: reverting =============================================
== 20201129113758 Hoge: reverted (0.0000s) ====================================

再度状態を確認します。

 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

downになっていますね!
これでこちらのファイルを削除をすることができます。

rm -rf db/migrate/20201129113758_hoge.rb

実行後もう一度確認します。$ 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

消えていますね!作業は以上になります。

記事を書くのはなかなか大変ですね、Makdown覚えなくては! 笑

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?