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.

マイグレーションファイルを変更する方法(Rails)

Posted at

マイグレーションファイル変更する方法

参考にしたサイト Railsチュートリアル(5.1)

$ rails db:rollback
$ rails db:migrate VERSION=0
$ rails db:rollback STEP=○
  • 1つ前の状態に戻します。
  • 最初の状態に戻したいときはVERSION=0つける
  • 最後のマイグレーションファイルから数えて戻したい数だけ戻せる
$ rails db:rollback
$ rails db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200830060821  Devise create users
  down    20200830062141  Create books

$ rails db:migrate:statusを使うことで変更できるファイルの一覧を確認できます。
downが変更可能でupが変更できないファイルです。
$ rails db:rollbackを使うとdownに変更されていると思います。

$ rails g migration add_index_to_users_email

usersテーブルの中にemailカラムをを追加するコマンド

おまけ

$ rails db:migrate 
$ bundle exec rake db:migrate 
  • Rails 5以降のコマンド
  • Rails 4以前のコマンド
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?