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`)
?