Why Is Rake Db:Migrate:Reset Not Listed in Rake -T

Why is rake db:migrate:reset not listed in rake -T?

Tasks that don't have a description will not show up.

EDIT: Looks like DHH removed the description from Rails 3 for a few tasks to 'cut down on noise'. rake db:setup has a note about db:reset though.

http://github.com/rails/rails/commit/983815632cc1d316c7c803a47be28f1abe6698fb

rake db:migrate does nothing, even on reset

After hours of deep debugging in rake, reinstalled all my complete setup, I finally figured out that the problem was comming from the "non so special" characters [ or ] somewere in my project path!!

DAMN RAILS!

Due to readability, all my project's folders start with "[NAME-OF-PROJECT]xxxx/"... then in this particular rails project comes a subfolder for the rails app.

No error, nothing that point you out that the path name could be the issue. I'm quite sur that "[" and "]" are not forbidden character (even on linux) : http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

And why "[" or "]" makes rake db:migrate failing and not rake db:migrate:status???

For me it clearly shows some weakness in rails architecture. I should probably do a bug report for that... can someone point me some report mailing list or whatever?

I hope that my misadventure will save hours for others.

rake db:migrate does not change table

Difference between rake db:migrate db:reset and db:schema:load has a great explanation of what the various rake db:* commands do.

Because rake db:reset performs a db:schema:load, it's loading the old columns from your table, rather than calling db:migrate, this is why your migration isn't being run.

Consider writing a migration that changes the names of those columns, rather than re-creates an existing table, or manually run rake db:drop; rake db:create db:migrate

rake db:reset does not populated data

I think you're reading the wrong line in the source. As I read it:

db:migrate:reset # => [:drop, :create, :migrate]

db:reset # => [:drop, :setup]

So db:reset just create the tables and sets the migrations as if they had been run, without actually running them. db:migrate:reset actually runs each migration.

rake db:migrate is not working

Try to rebuild your database structure(WARNING: all db-data will be lost):

rake db:drop:all
rake db:create:all
rake db:migrate

If you use Rails < 4.1, don't forget to prepare test database:

rake db:test:prepare

This is the easiest solution since you are working with tutorial. However in production or having important data in development you should take time to investigate the issue. In this case you most likely had created an empty migration, ran rake db:migrate, then added instructions to the migration, so you don't see a new field and further rake db:migrate does nothing. To resolve this issue you need to comment your change instructions, perform rake db:rollback, uncomment instructions and then rake db:migrate to apply instructions you missed.

Difference between rake db:migrate db:reset and db:schema:load


  • db:migrate runs (single) migrations that have not run yet.

  • db:create creates the database

  • db:drop deletes the database

  • db:schema:load creates tables and columns within the existing database following schema.rb. This will delete existing data.

  • db:setup does db:create, db:schema:load, db:seed

  • db:reset does db:drop, db:setup

  • db:migrate:reset does db:drop, db:create, db:migrate

Typically, you would use db:migrate after having made changes to the schema via new migration files (this makes sense only if there is already data in the database). db:schema:load is used when you setup a new instance of your app.



For rails 3.2.12:

I just checked the source and the dependencies are like this now:

  • db:create creates the database for the current env

  • db:create:all creates the databases for all envs

  • db:drop drops the database for the current env

  • db:drop:all drops the databases for all envs

  • db:migrate runs migrations for the current env that have not run yet

  • db:migrate:up runs one specific migration

  • db:migrate:down rolls back one specific migration

  • db:migrate:status shows current migration status

  • db:rollback rolls back the last migration

  • db:forward advances the current schema version to the next one

  • db:seed (only) runs the db/seed.rb file

  • db:schema:load loads the schema into the current env's database

  • db:schema:dump dumps the current env's schema (and seems to create the db as well)

  • db:setup runs db:create db:schema:load db:seed

  • db:reset runs db:drop db:setup

  • db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:rollback db:migrate) depending on the specified migration

  • db:migrate:reset runs db:drop db:create db:migrate

For further information please have a look at https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/railties/databases.rake (for Rails 3.2.x) and https://github.com/rails/rails/blob/v4.0.5/activerecord/lib/active_record/railties/databases.rake (for Rails 4.0.x)

rake db:rollback not working?

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.



Related Topics



Leave a reply



Submit