[Rails] "rake migrate" runs old migration

njmacinnes at gmail.com njmacinnes at gmail.com
Sun Apr 2 21:48:27 GMT 2006


You can do "rake migrate VERSION=4"... but that doesn't necessarily
fix the problem, because if it thinks its currently on a different
version to what it is, it still won't work.

The problem could have been caused by an error in your migration code.
When you run it and it's interrupted midway through, it'll stop
between versions, so even if you subsequently fix the code, it'll
still cause an error. In my experience, Rails 1.1 is better at
detecting errors in the migration code before it actually runs it, but
it's still not perfect. If your code is stuck between versions, there
are two ways you can fix it:

1. Delete everything and then run rake migrate again. This is fine if
you're in development and don't have lots of data in the tables (other
than data created by migration), but if you do have data, this can be
a problem.

2. Find out what version the code is breaking at (rake migrate
--trace) then manually do what you need to in the database to complete
the migrate or roll back to the previous version.

Hope this helps.
-Nathan

On 02/04/06, Craig White <craigwhite at azapple.com> wrote:
> On Sun, 2006-04-02 at 22:51 +0200, Ingo Weiss wrote:
> > Hi,
> >
> > I created a new migration with "script/generate migration", but when I
> > try to run it with "rake migrate" it looks like the old migration runs
> > again (which generates an error since it tries to create a table that's
> > there).
> >
> > How does Rails figure out which migration to run?
> ----
> The 'version' column of the 'schema_info' table in your appropriate db
> ----
> >  Can I explicitly run a
> > specific migration to work around the problem?
> ----
> I suppose if you manually change the 'version' of the 'schema info' -
> never tried it myself
> ----
> >  What might have caused it
> > in the first place?
> ----
> - never successfully migrated that db
> - restored db from a dump that didn't have 'schema_info' table
> - deleted schema_info table
> probably others
> ----
> > This happened after I upgraded to Rails 1.1 so I am wondering whether
> > this could have something to do with it.
> ----
> perhaps, perhaps not.
>
> did you do 'rake rails:update' to your rails app after you upgraded
> rails?
>
> Craig
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


More information about the Rails mailing list