How to delete migration files in Rails 3

前端 未结 11 1047
盖世英雄少女心
盖世英雄少女心 2020-12-07 07:54

I would like to remove/delete a migration file. How would I go about doing that? I know there are similar questions on here but as an update, is there a better way than doin

相关标签:
11条回答
  • 2020-12-07 08:31

    Sometimes I found myself deleting the migration file and then deleting the corresponding entry on the table schema_migrations from the database. Not pretty but it works.

    0 讨论(0)
  • 2020-12-07 08:32

    Look at 4.1 Rolling Back

    http://guides.rubyonrails.org/migrations.html

    $ rake db:rollback

    0 讨论(0)
  • 2020-12-07 08:32

    I just had this same problem:

    1. rails d migration fuu -this deleted the migration with the last timestamp
    2. rails d migration fuu -this deleted the other migration
    3. use git status to check that is not on the untracked files anymore
    4. rails g migration fuu

    That fixed it for me

    0 讨论(0)
  • 2020-12-07 08:33

    I usually:

    1. Perform a rake db:migrate VERSION=XXX on all environments, to the version before the one I want to delete.
    2. Delete the migration file manually.
    3. If there are pending migrations (i.e., the migration I removed was not the last one), I just perform a new rake db:migrate again.

    If your application is already on production or staging, it's safer to just write another migration that destroys your table or columns.

    Another great reference for migrations is: http://guides.rubyonrails.org/migrations.html

    0 讨论(0)
  • 2020-12-07 08:39

    Side Note: Starting at rails 5.0.0 rake has been changed to rails So perform the following

    rails db:migrate VERSION=0

    0 讨论(0)
  • 2020-12-07 08:41

    We can use,

    $ rails d migration table_name  
    

    Which will delete the migration.

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