title: How to avoid crashing Rails app after removing column from table?
body: <h2>The problem</h2>
  
  <p>I just learned that our current practice for removing a column in an ActiveRecord migration is to hide the column from Rails before actually removing it (via an ugly hack, see below for details).</p>
  
  <p>This is due to the fact that Rails caches the <code>SHOW FULL FIELDS</code> query. If we don't work around that, the (long-running) migration will remove the column and by that time, Rails will have already cached the fields. Once the migration is done and the column is gone, the app will subsequently crash because <code>INSERT</code>s will provide values for a non-existing column because of the cache.</p>
  
  <p>Using things like <code>clear_table_cache!</code> within the migration are of no use because we deploy to N servers and run the migration on just one of them. This would clear the cache on one of the servers but not all.</p>
  
  <h2>Our current solution (a.k.a. ugly hack)</h2>
  
  <p>What we're currently doing is overriding <a href="https://github.com/rails/rails/blob/602ec7a4a21846db74f0371eb27784f19f80e28c/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb#L576-L587" rel="noreferrer"><code>ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#columns</code></a> in an initializer and deploy that before running the migration.</p>
  
  <p>After the migration is done, we remove the overriding initializer and deploy again.</p>
  
  <p>At this point, I cannot believe we're the only ones who encounter this problem and have to work around it. <strong>Are there any other solution to this problem?</strong></p>