Rails reset_column_information

Occasionally when I’m writing a new migration I encounter a strange error where models are not behaving as they should. I usually encounter the problem with large Rails apps that have a long history of migrations.

The symptom of the problem is that a model object returns nil for an attribute even though I have set the attribute and saved the record. When investigating the situation with pry I find that the model is missing a number of fields!

The problem is that the information Rails holds in memory, about the model, has become out of date. You can reset the cache using reset_column_information: