reset_column_information not called after each migration #6939

lulalala opened this Issue Jul 3, 2012 · 4 comments


None yet

4 participants

lulalala commented Jul 3, 2012

I have made a demo app ( to demonstrate the issue. The readme shows the step to prepare the database, and reproduce the error.

Basically I have a migration B which adds a new column, and a migration C to fill that column. It works okay if those B & C are to run in one go. However I have a migration A which basically does some lookup, and when running A, B and C together, migration C won't update column at all.

If I explicitly call Item.reset_column_information at the end of migration A, then the bug disappears. Therefore I suspect that reset_column_information is not called after each migration (which I think it should).

I am using Rails 3.2.6 and Ruby 1.9.3

kytrinyx commented Jul 3, 2012

I believe this is the expected behavior.

Using models in your migration is considered iffy, and as such I'd expect that you're expected to jump through a hoop or two in order to do so.

The Rails Guide has a section about using models in your migration:

The example they use has a single migration with both the structural change and the data change in the same migration, and they clearly expect the developer to call reset_column_information.

If I'm reading this correctly, then column information is read in when the connection to the database is established.

All the pending migrations are run using the same connection pool, and therefore column information would not be expected to be refreshed until the next time you connect (e.g. the next time you run rake db:migrate).

lulalala commented Jul 4, 2012

I believe that when multiple migrations are run, it should behave the same if I run them separately or run them together.

And the API said

Sometimes you’ll want to add a column in a migration and populate it immediately after. In that case, you’ll need to make a call to Base#reset_column_information

I take the meaning of immediate as being "within the same migration". And in my case I am using the model before the migration, and in different migration files. Which is completely different to what the API specify users to use reset_column_information.

drogus commented Jul 4, 2012

@lulalala I would say that this is a documentation issue, not code issue, as @kytrinyx points out.

Technically, we could run reset_column_information after each migration, but I'm not sure if there aren't any implications.

@tenderlove @jonleighton do you think about that? Is it safe to change this behavior? Is it worth it?


Closed by #7050

@metaskills metaskills referenced this issue in rails-sqlserver/activerecord-sqlserver-adapter Jan 14, 2013

Fixes issue 237: "No such column" when renaming some columns in the migrations #246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment