I followed the advice of this SO post. An entree belongs_to a venue. So I expect a foreign key named venue_id on the entrees table. I generated the following:
rails g migration AddEntreeToVenue entree:belongs_to
It created the following migration:
class AddEntreeToVenue < ActiveRecord::Migration[5.0]
def change
add_reference :venues, :entree, foreign_key: true
end
end
But after running db:migrate, I look at the entrees table and no foreign key:
Indexes:
"entrees_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "venues" CONSTRAINT "fk_rails_0cf11999c6" FOREIGN KEY (entree_id) REFERENCES entrees(id)
What it appeared to do was add the foreign key to the venues table, not the entrees table. What did I do wrong?