cinvro
cinvro

Reputation: 115

don't know how to build task "db:rollback"

I am using rake 0.8.7 and rails 1.2.3 now. And when I want to do some db migration stuff using rake, it shows no complain when I type in "rake db:migrate". But when I use "rake db:rollback", it gives messages:

don't know how to build task "db:rollback"

Actually, all other commands except "migrate" do not work on my machine. such as rake db:migrate:up or rake db:version, they all give "don't know how to build task" error.

Any suggestion?

Upvotes: 0

Views: 1453

Answers (2)

Mike Mackintosh
Mike Mackintosh

Reputation: 14237

Edit your Rakefile to include:

namespace :db do
  desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
  task :rollback => :environment do
    step = ENV['STEP'] ? ENV['STEP'].to_i : 1
    version = ActiveRecord::Migrator.current_version - step
    ActiveRecord::Migrator.migrate('db/migrate/', version)
  end
end

Some project templates leave the rollback task out of Rakefile, which is dumb.

Upvotes: 1

Ron
Ron

Reputation: 1166

That's a newer rake command. With your old version of rake, you'll have to do rake db:migrate:down VERSION=xxxx

Upvotes: 1

Related Questions