Cannot get reference id by using underscore(product_order) on rails
<p>Create Model using:</p>

<pre><code>rails g model Product product_name:string
rails g model ProductCategory category_name:string

class Product &lt; ActiveRecord::Base
  belongs_to :product_category
end

class ProductCategory &lt; ApplicationRecord
  has_many :products
end
</code></pre>

<p>And How to reference the category id(ProductCategory) into product?
And I do and edit migration below:</p>

<pre><code>class AddProductCategoryToProducts &lt; ActiveRecord::Migration[5.0]
  def change
    product_category = ProductCategory.create! category_name: "No category"
    add_reference :products, :product_category, foreign_key: true, default: product_categories_id
  end
end
</code></pre>

<p>After that i run rake db:migrate and got error:</p>

<pre><code>== 20160716050030 AddCourseCategoryToCourses: migrating =======================
-- course_categories_id()
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined local variable or method `course_categories_id' for #&lt;AddCourseCategoryToCourses:0x007fabfd2667d0&gt;
</code></pre>