OUR BLOG

Thoughts on development, design and the world we live in.



Heroku Migration Fails to Update Attributes: reset_column_information

By LiahHansen in Uncategorized. Posted on December 2nd

On several occasions I’ve had Heroku apps fail to recognize columns I add to the database. The symptoms of this problem are:

  • The app throws an error if you visit a page with the new methods referencing the column names
  • If you use heroku console and create your new object it won’t have the attributes for your new column.

This happened to me yesterday and here is how to fix it. First, I made sure that the migration had taken effect. I used the handy heroku sql console plugin which allows you to execute sql on your Heroku database. This allowed me to checkout the schema_migrations table and make sure my latest migration was there:

[code]SELECT * FROM schema_migrations;[/code]

Then I looked at the table with the added columns to see if it had the changes:

[code]DESCRIBE courses;[/code]

The columns were there.

The reset_column_information method turned out to be the key to fixing this problem:

[code]
heroku console
>> Course.reset_column_information
[/code]

Now Course had the recently added attributes. To avoid this problem next time, I’ll use reset_column_information inside of the migration when I change an existing model’s attributes. An additional facet to this solution is that if you access a model class in a migration, you need to open up the class in the migration:

[code]
class Course < ActiveRecord::Base; end
[/code]

Here are some resources:

6 Comments

  1. Bob
    Posted December 13, 2010 at 10:37 am | Permalink

    Thanks so much was having the same problem and this solved it!

  2. Pascal
    Posted December 21, 2010 at 1:30 pm | Permalink

    I encountered the same weird problem. Thanks for pointing out this solution. It worked like a charm!

  3. Posted January 3, 2011 at 9:41 pm | Permalink

    Wow! Perfect timing. I wasn’t able to figure out how to do this by reading Heroku’s site. You just saved me a ton of time, thanks!

  4. Christoph
    Posted January 27, 2011 at 7:19 am | Permalink

    Thanks, was messing around now for an hour to figure out what’s happening.

  5. Scott
    Posted May 6, 2011 at 10:39 am | Permalink

    Thank you! Just ran into this bizarre issue with Heroku this morning. Oddest errors were popping up, but I definitely narrowed it down to the new columns. This will really help (hopefully) preventing this in the future. Now I’m wondering if it’s a bug with Heroku or Postgres… Any thoughts?

  6. Posted May 30, 2012 at 12:18 pm | Permalink

    Thanks man. Much appreciated tip :). This was happening to me locally as well.

Post a Comment

Your email is never shared. Required fields are marked *

*
*