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

[Rails] rails db:migrate してもなぜかmigrationファイルが無視されるとき

Posted at

Versions

$ ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
$ bundle exec rails -v
Rails 5.1.7

症状

こういうことが起きた。

まず、migrateされていないmigrationファイルがあることを確認。

$ bin/rails db:migrate:status

database: database名

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200101xxxxxx  Devise create users
              ...()
  down    20200101xxxxxx  Drop users

OK!(`・ω・´)

では、migrateしよう。

$ bin/rails db:migrate
Model files unchanged.

ほう....何も変わらないと。
では、再度migrate状況を確認しよう。

$ bin/rails db:migrate:status

database: database名

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200101xxxxxx  Devise create users
              ...()
  down    20200102xxxxxx  Drop users

終わってないじゃないかあぁぁああorz

対策

db:migrate:redo で解決した

$ bin/rails db:migrate:redo VERSION=20200102xxxxxx
Model files unchanged.
== 20191125071019 DropUsers: migrating ============================
-- drop_table(:users)
   -> 0.0046s
== 20191125071019 DropUsers: migrated (0.0047s) ===================

なんなんじゃい!!(´;ω;`)

発生状況

同じmigrationファイルに対してrollbackとmigrateを何度も繰り返していたら発生した。
migrationファイル自体の書き換えも発生していた。
もしかしたら、railsで管理している内部データか何かが壊れたのではないかと疑っている。

面倒なので詳細は掲載しませんが、migrate:statusの結果とDB本体(mysql)のテーブルの状況は正しく一致していました。

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