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.

rollbackできないエラーの時

Posted at

rollbackをしようと実装していた矢先、以下のようなエラーが出て、少しはまってしまったため、その備忘録を書かせて頂きます。

ActiveRecord::UnknownMigrationVersionError: 
No migration with version number 20220703020507.

このエラーはどう言う時に出るかというと、下記の表で上から三行目に
[********** NO FILE **********]と書かれてるように、NO FILEがあると、うまくrollbackができなくなってしまいます。

database: starbuck_services2_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20220702022539  Sorcery core
   up     20220702115611  Add role to users
   up     20220703020507  ********** NO FILE **********
   up     20220705060146  Create posts
   up     20220705062125  Create categories
   up     20220705062158  Add category id to posts
   up     20220706032605  Add photos to posts
   up     20220707040615  Add evaluation to post
  down    20220711013102  Create comments

解決方法は、一度datebaseを削除することで、うまくいきます。

bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:migrate:status

上から順に削除、作成、migrate、確認といったところです。

database: starbuck_services2_development

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20220702022539  Sorcery core
   up     20220702115611  Add role to users
   up     20220705060146  Create posts
   up     20220705062125  Create categories
   up     20220705062158  Add category id to posts
   up     20220706032605  Add photos to posts
   up     20220707040615  Add evaluation to post
   up     20220711013102  Create comments

同じようなエラーにはまっている人の少しでも役に立てたら幸いです。

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?