I understand that by default the id
field is created and also: PRIMARY KEY (
id)
.
How about the foreign key ?
I have
You can use the foreigner gem for adding foreign keys to your application. To get started add the following to your Gemfile
gem "foreigner"
After that you can easily add foreign keys in your migration like so:
add_foreign_key :products, :shops
This would add a foreign from product.shop_id
to shop.id
. See the documentation for more options like differently named keys or self-referencing tables.