views:

65

answers:

1

I would like to remove/delete a migration file. How would I go about doing that? I now 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?

Thanks in advance.

A: 

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. See this cheat sheet for more details: http://bit.ly/9moWcB

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

Fábio Batista
Would deleting the migration and then running a db:migrate wipe out the table that was created?
alvincrespo
No, since Rails would not know how to delete it. It needs to call the `self.down` method defined on your migration to "downgrade" your database.
Fábio Batista
I just edited my response with 2 good references, check that out.
Fábio Batista
Oh, I see. Ok, thanks, this is exactly what I was wondering about. Thanks Again!
alvincrespo