How to delete migration files in Rails 3

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 doing script/destroy?

Also, should I do a db:reset or db:drop if I remove/delete a migration?


I usually:

  • Perform a rake db:migrate VERSION=XXX on all environments, to the version before the one I want to delete.
  • Delete the migration file manually.
  • If there are pending migrations (ie, 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


    Another way to delete the migration:

    $ rails d migration SameMigrationNameAsUsedToGenerate
    

    Use it before rake db:migrate is executed because changes in database will stay forever :) - or remove changes manually


    Run below commands from app's home directory:

  • rake db:migrate:down VERSION="20140311142212" (here version is the timestamp prepended by rails when migration was created. This action will revert DB changes due to this migration)

  • Run "rails destroy migration migration_name" (migration_name is the one use chose while creating migration. Remove " timestamp_ " from your migration file name to get it)

  • 链接地址: http://www.djcxy.com/p/56896.html

    上一篇: Rails rake db:使用生成的模型迁移异常终止

    下一篇: 如何在Rails 3中删除迁移文件