title: rails PG undefined column does not exist for index creation
body: <p>I'm trying to add an index for a for column but I'm getting the error:</p>
  
  <pre><code>ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "contact" does not exist
  : CREATE UNIQUE INDEX  "index_users_on_contact" ON "users"  ("contact")
  </code></pre>
  
  <p>which is strange because as you an see I'm creating the column before I try to index it:</p>
  
  <pre><code>class AddContactToUser &lt; ActiveRecord::Migration[5.1]
    def change
      add_reference :users, :contact, foreign_key: true
      add_index :users, :contact, unique: true
    end
  end
  </code></pre>
  
  <p>Why am I getting this error?</p>
  
  <p>In case your wondering why I'm doing a separate contact model, it's because all users will have a contact but not all contacts will have a user.</p>