title: First db migration on Heroku: undefined table/relation doesn't exist for foreign key
body: <p>Error message: <code>PG::UndefinedTable: ERROR:  relation "resolvers" does not exist</code></p>
  
  <p>Here's the migration that is spitting out the error:</p>
  
  <pre><code>class AddResolverRefToBugs &lt; ActiveRecord::Migration[5.0]
    def change
      add_reference :bugs, :resolver, foreign_key: true
    end
  end
  </code></pre>
  
  <p>Now, I get that there is no Resolver table, since the actual table is the User table; resolver_id is my foreign_key column.  So  I just have a <code>resolver_id</code> field for one of my models that references the Users model, and I've not had any issues with my app in the dev environment.</p>
  
  <pre><code>class Bug &lt; ApplicationRecord
    # Associations
    belongs_to :user
    belongs_to :resolver, class_name: 'User', optional: true
  </code></pre>
  
  <p>Am I supposed to specify something, somewhere such that PG would know :resolver (the resolver_id column) is in fact the Users table?</p>
  
  <p>My error message contains the line: <code>: ALTER TABLE "bugs" ADD CONSTRAINT "fk_rails_2d3f1765bb" FOREIGN KEY ("resolver_id") REFERENCES "resolvers" ("id")</code></p>
  
  <p>So it does look like it's referencing the wrong thing.</p>
  
  <p>In one relevant <a href="https://stackoverflow.com/questions/38637655/deploying-rails-app-to-heroku-environment-data-not-found-in-the-schema">StackOverflow question</a>, I noticed that he/she has "nested" references...</p>
  
  <pre><code>create_table :english_grades do |t|
    t.references :teacher, references: :users
    t.references :student, references: :users
  </code></pre>
  
  <p>...where users is specified.  I'm not sure if that is relevant here.</p>
  
  <p>Presumably my schema my migration might have to look like:</p>
  
  <p><code>t.references :resolver, references: users</code></p>
  
  <p>The <a href="https://apidock.com/rails/v4.0.2/ActiveRecord/ConnectionAdapters/SchemaStatements/add_reference" rel="nofollow noreferrer">docs for add_references</a> don't mention anything about this.</p>
  
  <p>That person also has foreign keys specified in the migration, where I do see a link that goes from the foreign key field to the actual table.  Presumably I'd need something like this:</p>
  
  <p><code>add_foreign_key :bugs, :users, column: :resolver_id</code></p>
  
  <p>But based on what I read online, it's not necessary to use <code>add_foreign_key</code>.</p>
  
  <p>I would appreciate any explanation here.</p>
  
  <p>Note: Some have suggested running db:reset first, but that doesn't work for me, as I get the <a href="https://stackoverflow.com/questions/38637655/deploying-rails-app-to-heroku-environment-data-not-found-in-the-schema">error this person is getting</a>.</p>