This project is archived and is in readonly mode.

#1209 ✓duplicate
Nathaniel Bibler

'rake db:migrate:redo' fails to update schema.rb

Reported by Nathaniel Bibler | October 13th, 2008 @ 06:05 PM | in 2.x

In Rails 2.1.1, the rake db:migrate:redo properly reverts the db/schema.rb file, but fails to update db/schema.rb upon migration completion.

The following commands reproduce the issue:

$ rails testing_app
$ cd testing_app
$ ./script/generate model Foo name:string
$ rake db:migrate
$ cat db/schema.rb

ActiveRecord::Schema.define(:version => 20081013165823) do

  create_table "foos", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"


$ rake db:migrate:redo
$ cat db/schema.rb

ActiveRecord::Schema.define(:version => 0) do


Comments and changes to this ticket

  • Tyler Rick

    Tyler Rick November 14th, 2008 @ 08:53 PM

    I wasted a fair bit of time today trying to figure out why when my specs didn't have the latest changes I'd made to the schema (and were failing as a result). Finally I tracked it down to this bug.

    As a workaround, you can always do rake db:migrate:redo; rake db:schema:dump... but who wants to do that? So I decided to investigate a little further...

    If you run rake db:schema:dump --trace you will notice that although both db:rollback and db:migrate invoke db:schema:dump, only the first "invoke" results in an **Execute** db:schema:dump.

    ** Invoke db:migrate:redo (first_time)
    ** Invoke db:rollback (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute db:rollback
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment
    ** Execute db:schema:dump
    ** Invoke db:migrate (first_time)
    ** Invoke environment
    ** Execute db:migrate
    ** Invoke db:schema:dump
    ** Execute db:migrate:redo

    It turns out that Rake will only "invoke" a task once.... which works out great for tasks like "environment", which are given as a prerequisite to a lot of tasks and only actually NEED to be invoked once, but as this ticket proves, there are times when you just want to simply execute a task unconditionally without consideration as to whether it's been run already or not.

    I wish Rake provided a standard method to unconditionally invoke a task. But since it doesn't, I wrote my own invoke_again method. It's not pretty but it works. (See attached patch.)

    ** Execute db:migrate
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment
    ** Execute db:schema:dump
    ** Execute db:migrate:redo
  • Charles

    Charles December 2nd, 2008 @ 02:34 PM

    Thanks Tyler-

    Your patch works great, and saved me some Advil.

  • CancelProfileIsBroken

    CancelProfileIsBroken March 7th, 2009 @ 02:39 PM

    • State changed from “new” to “duplicate”

    Fixed on #1412

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 19th, 2010 @ 07:09 AM

    • Tag changed from 2.1-stable, 2.1.1, bug, migration, migrations, rake to 2.1-stable 2.1.1 bug bug migration migrations rake
    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>