7
據我所知,默認情況下,id
字段已創建,還有:PRIMARY KEY (
id )
。什麼在Ruby on Rails 3中創建FOREIGN KEY約束?
外鍵怎麼樣?
我有Shops
和Products
表和以下關聯:
Shop: has_many :products
Product: belongs_to :shop
在Product
我也有:
t.integer "shop_id"
其目的是要爲外鍵,也:
add_index("products", "shop_id")
但是,如果我導出我看到的數據庫LY:
KEY `index_products_on_shop_id` (`shop_id`)
我應該怎麼才能做補充
FOREIGN KEY (`shop_id`) REFERENCES Shop(`id`)
?