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 5 years have passed since last update.

ロールバックせずにマイグレーションファイルを削除する方法

0
Last updated at Posted at 2020-12-19

<この記事について>
自作のアプリ製作中にカラム修正のために、マイグレーションファイルを削除。
毎回ロールバックして削除するのが手間で、他の方法を学んだので備忘録として投稿します!

[環境]
・Ruby 2.6.5
・Rails 6.0.0
・macOS

まずは、以下のコマンドを実行してマイグレーションファイルの現状を確認しましょう!

$ bundle exec rake db:migrate:status

次はステータスの確認です。

一番左の"Status"が"up"となっているものは修正など一切できない状態なので、"down"にする必要があります。

削除したいファイルが"up"になっている場合は、以下のコマンドで"down"にします。

$ bundle exec rake db:migrate:down VERSION=(削除したいファイルのMigration ID_Migration Name).rb  
  * IDとNameを"_"で繋いで".rb"を後ろに足す。

もう一度ステータスを確認しましょう!

$ bundle exec rake db:migrate:status

削除したいファイルが"down"になっていれば、あとは削除して完了です!

  • "down"にならない人は数字や誤字を確認して下さい。
$ rm -rf db/migrate/(削除したいファイルのMigration ID_Migration Name).rb

無事に消えましたか?

自分自身、初学者のため分かりにくい点もあったかと思いますので、徐々に改善できるように日々改善していきます🙇‍♂️

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?