Migration reports success but did not do anything

1 view
Skip to first unread message

NY

unread,
Oct 31, 2011, 2:48:22 PM10/31/11
to Ruby on Rails: Talk
I observed this a few times, but not always happen, and if I down the
migration and run again, it often works.

My migration is really simple like:

Foo.find_each do |foo|
foo.update_attribute(:bar, "baz")
end

Occasionally, it reports success, but not actually updated the
attribute for the "bar" column of Foo object. It appears to just skip
the whole thing and report success. And as I said, if I down it and
run again, it has always worked.

Anybody else has seen this problem before? I'm using Rails 3.0.10 but
I had this problem with older 3.0.x versions as well.


Tim Shaffer

unread,
Oct 31, 2011, 3:05:23 PM10/31/11
to rubyonra...@googlegroups.com
So whenever you migrate down and back up it works? Sounds like the migration is working properly then.

Under what circumstances does it not work?

NY

unread,
Oct 31, 2011, 6:05:08 PM10/31/11
to Ruby on Rails: Talk
That's exactly what I try to figure out. Migrations like this randomly
get "skipped" (reported success but didn't do anything).

It doesn't happen consistently (and doesn't happen most of time).

Frederick Cheung

unread,
Oct 31, 2011, 6:53:28 PM10/31/11
to Ruby on Rails: Talk
Failed validations? You do have to be a little careful when using
models in migrations. Consider this scenario:

- The migration above is written
- A new validation is written and a migration that fixes the data
already present in the database is written

if you try and run both of these migrations in one go then the updates
in the first migration fail, because the latest validations are used.
if you try and run the migration a second time they succeed because by
now the data fixing migration has run. The way to get around this
particular problem is to use copies of the model in your migration
(the migrations guide on guides.rubyonrails.org discusses this)

Fred
Reply all
Reply to author
Forward
0 new messages