rake db:rollback not working?

前端 未结 4 991
半阙折子戏
半阙折子戏 2020-12-24 11:12

I\'m writing my first Rails app. I\'ve run a few rails generate model ... and rake db:migrate commands, but I now want to change my data model and

相关标签:
4条回答
  • 2020-12-24 11:27

    NOTE: Use the suggestions with caution, it is very dangerous for non-dev environments.


    If

    rake db:migrate:status
    

    gives you a migration that says

    up 20120702151447 ********** NO FILE **********

    Then the best thing to do would be to do a (note that the following command will drop the database):

    rake db:reset
    

    to redo all migrations. If the last migration is the one missing, then schema.rb will have the last migration that rake db:migrate will look for:

    ActiveRecord::Schema.define(:version => 20120702151447) do

    Change that number to the last one in your migrate folder.

    0 讨论(0)
  • 2020-12-24 11:33

    Solution (see my comment): run

    rake db:migrate:status
    

    and correct problems you find there. In this case (per @MarkThomas' followup), you might want to check all files you need are in place.

    0 讨论(0)
  • 2020-12-24 11:42

    This is what worked for me. Combine the steps given in this answer and comment by dB.

    1. run rake db:migrate:status
    2. If you have a ****NO FILE**** entry, just note the version number as noFileVersion. Note the version of the entry just above no file entry(stable_version).
    3. created a "dummy" file with name noFileVersion_create_nothing.rb, and body
    class CreateNothing < ActiveRecord::Migration 
      def change 
      end 
    end
    
    1. run rake db:migrate VERSION=stable_version
    2. remove the noFileVersion_create_nothing.rb manually.
    3. run rake db:migrate.
    4. run rake db:migrate:status again to check if No file entry has disappeared.
    0 讨论(0)
  • 2020-12-24 11:49

    The following worked for me: rake db:migrate:down VERSION=20190304092208

    Version number can be obtained by the following command: rake db:migrate:status

    This was the last version number to rollback one last migration

    0 讨论(0)
提交回复
热议问题