1
1

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.

【Rails】マイグレーションファイルを削除する手順と方法

Last updated at Posted at 2021-06-26

#対象者
マイグレーションファイルの確認・削除・モデルとの紐付けの方法

#手順目次
1.データベースとモデルが紐付いているのか確認しよう!

2.down or upを確認

3.rails db:migrate:statusで再確認

#実際の手順
###1.データベースとモデルが紐付いているのか確認 → rails db:migrate:status

$ rails db:migrate:status

実行するとこうなる↓


database: /home/ec2-user/environment/bookers3/db/development.sqlite3

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20210624050145  Devise create users
   up     20210626043822  Create books
  down    20210626044439  Add profileimagedid to users
  down    20210626044515  Add introduction to users

###2.down or upを確認
①down → 削除してOK
②Up  → コマンドを打ち込んでdownにする(紐付けを解く)
rails db:migrate:down VERSION=(作成日時)

$ rails db:migrate:down VERSION=20210626044439
== 20210626044439 AddProfileimagedidToUsers: reverting ========================
-- remove_column(:users, :users, :string)
   -> 0.0100s
== 20210626044439 AddProfileimagedidToUsers: reverted (0.0148s) ===============

⚠作成日時は下記画像の赤線部分
スクリーンショット 2021-06-26 15.17.08.png

###3.再度紐付いているかどうか確認 → rails db:migrate:status

$ rails db:migrate:status

database: /home/ec2-user/environment/bookers3/db/development.sqlite3

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20210624050145  Devise create users
   up     20210626043822  Create books
   up     20210626052506  Add introduction to users
   up     20210626052540  Add profileimagedid to users

全部アップになっていることを確認

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?