title: How to add foreign key in rails migration with different table name
body: <p>How can I assign different table name with adding foreign key. for e.g</p>
  
  <p>I have a model like</p>
  
  <pre><code>class MyPost &lt; ActiveRecord::Base
    has_many :comments, class_name: PostComment
  end
  
  class PostComment &lt; ActiveRecord::Base
    belongs_to :post, class_name: MyPost
  end
  </code></pre>
  
  <p>Now i want to change my migration file like this:</p>
  
  <pre><code>class CreatePostComments &lt; ActiveRecord::Migration
    def change
      create_table :post_comments do |t|
       t.belongs_to :post, index: true
       t.timestamps null: false
      end
      add_foreign_key :post, :class_name =&gt; MyPost
    end
  end 
  </code></pre>
  
  <p>But it is not working. Migration is getting cancelled. How do I change my migration file to work with my model structure.</p>