0

I'm trying to test my migrations from the version=0 to the last version, however when I run rake db:migrate version=0 it doesn't remove any table.

Why?

juliano.net
  • 7,982
  • 13
  • 70
  • 164
  • http://stackoverflow.com/questions/4116067/purge-or-recreate-a-ruby-on-rails-database – AbM Jun 04 '15 at 00:20

2 Answers2

3

Don't test your migrations all the way through. Migrations are just for applying changes to the database, not for building it from scratch - that's what schema.rb is for.

To rebuild your database from scratch, use rake db:schema:load, which will build your database from schema.rb.

In fact, regarding migrations, some people will even delete migrations that are old and have run everywhere that they'll need to run. Really, there's no need to keep them around.

The more migrations you have to run at one time, the more likely you are to have issues. Don't even bother trying it, it's a futile exercise. You never need to do it.

joshua.paling
  • 13,762
  • 4
  • 45
  • 60
  • If I merge all my migrations to the schema.rb, what version should I place in the `ActiveRecord::Schema.define(version: xxxxx) do`? – juliano.net Jun 04 '15 at 00:57
  • I don't think you should ever need to "merge all migrations to the schema.rb". Rails will just automatically manage the schema.rb for you, and auto-generate it each time you do anything that means it should change. Rails will also automatically manage the version number for you. For more info, check out http://stackoverflow.com/questions/2979059/is-the-version-number-in-rails-schema-rb-used-for-anything – joshua.paling Jun 04 '15 at 04:49
0

You could try $ bundle exec rake db:rollback to unload the previous table.

Purry
  • 241
  • 1
  • 12