Avoiding Schema Cache Errors
When Active Record starts up, for each model that’s backed by a database table, the table fields are scanned and cached in the schema cache[118] for as long as the application is running.
Dropping a database column without considering Active Record and active instances of the application means that a schema change may cause an application error. This is due to the application trying to write or read to a cached column that’s been removed.
To drop a column safely, use the Active Record ignored_columns[119] mechanism. Add the field you’re planning to drop to this list, and deploy and restart the application instances.
A field added to ignored_columns, after the application has restarted, can safely be dropped from ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access