0
2

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

ご参考までに。

マイグレーションの状態を見る

upと表示されるのが実行済み、downは未実行です。

% bin/rails db:migrate:status

database: blog_rails6_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20191031052351  Create users
   up     20191031053247  Create entries
   up     20191031053324  Create tags
   up     20191031053328  Create taggings
   up     20191116013349  Create stars

1つロールバック

% bin/rails db:rollback
% bin/rails db:migrate:status

database: blog_rails6_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20191031052351  Create users
   up     20191031053247  Create entries
   up     20191031053324  Create tags
   up     20191031053328  Create taggings
  down    20191116013349  Create stars

特定のバージョンまで全部ロールバック

% bin/rails db:migrate VERSION=20191031053247
% bin/rails db:migrate:status

database: blog_rails6_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20191031052351  Create users
   up     20191031053247  Create entries
  down    20191031053324  Create tags
  down    20191031053328  Create taggings
  down    20191116013349  Create stars

特定のバージョンを1つ抜く

% bin/rails db:migrate:down VERSION=20191031053328
bin/rails db:migrate:status

database: blog_rails6_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20191031052351  Create users
   up     20191031053247  Create entries
   up     20191031053324  Create tags
  down    20191031053328  Create taggings
   up     20191116013349  Create stars

特定のバージョンのマイグレーションを1つ実行するには、db:migrate:up VERSION=バージョン とします。

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?