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 1 year has passed since last update.

rails マイグレーションファイルの操作一覧

Last updated at Posted at 2023-03-02

操作について、備忘として残します。

マイグレーションファイルの操作一覧

    
名前 説明
作成 rails g mode モデル名(単数形)
実行 rails db:migrate
修正 rails db:rollback
ステータス確認 rails db:migrate:status
削除 rails d model モデル名(単数形)

指定のマイグレーションファイルをロールバックしたい場合

①ステータスでDBのidを確認
②編集したいDBをdownにする
③編集
④DBをupにする
⑤ステータスでupになっていることを確認

#ステータスを確認
bundle exec rake db:migrate:status

#該当のMigration IDを指定して再編集
bundle exec rake db:migrate:down VERSION='マイグレーショID'

#再度ステータスを確認してDOWNになっていることを確認し、編集する

# 編集後再度マイグレーションする
bundle exec rake db:migrate:up VERSION='マイグレーショID'

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?