Avoid ActiveRecord "Unknown column 'table.column' in 'field list'" exception between dropping the column and application restart
If you just run migration with drop column statement ActiveRecord in your app instance will continue to issue queries with non-existing items in column list causing exceptions.
To avoid downtime deploy this initialzier before dropping columns.
model = MyModel
column_names = %w{ first_column second_column }
columns = model.columns.select do |c|
column_names.include?(c.name)
end
columns.each do |c|
model.columns.delete(c)
end
Written by Tomasz Werbicki
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#