title: How to do a reversible migration for add_column
body: <p>This migration works perfectly</p>
  <pre><code>class CreateCourses &lt; ActiveRecord::Migration[6.0]
    def change
      create_table :courses do |t|
        t.references :user, null: false, foreign_key: true
        t.string :title, limit: 500, null: false
      end    
      reversible do |dir|
        dir.up do
          add_column :users, :courses_count, :integer, null: false, default: 0
        end
        dir.down do
          remove_column :users, :courses_count
        end
      end
    end
  end
  </code></pre>
  <p>But when I run this it adds courses_count but it does <em>not</em> remove it on <code>rails db:rollback</code>. Isn't the point of reversible migrations with the <code>def change</code> method that it would reverse <code>add_column</code>?</p>
  <pre><code>class CreateCourses &lt; ActiveRecord::Migration[6.0]
    def change
      create_table :courses do |t|
        t.references :user, null: false, foreign_key: true
        t.string :title, limit: 500, null: false
       
        add_column :users, :courses_count, :integer, null: false, default: 0
      end    
    end
  end
  
  % rails db:migrate
  == 20200815181736 CreateCourses: migrating ====================================
  -- create_table(:courses)
  -- add_column(:users, :courses_count, :integer)
     -&gt; 0.0037s
     -&gt; 0.0258s
  == 20200815181736 CreateCourses: migrated (0.0259s) ===========================
  
  % rails db:rollback
  == 20200815181736 CreateCourses: reverting ====================================
  -- drop_table(:courses)
     -&gt; 0.0060s
  == 20200815181736 CreateCourses: reverted (0.0078s) ===========================
  
  % rails db:migrate 
  == 20200815181736 CreateCourses: migrating ====================================
  -- create_table(:courses)
  -- add_column(:users, :courses_count, :integer)
  rails aborted!
  StandardError: An error has occurred, this and all later migrations canceled:
  
  PG::DuplicateColumn: ERROR:  column &quot;courses_count&quot; of relation &quot;users&quot; already exists
  </code></pre>