What creates the FOREIGN KEY constraint in Ruby on Rails 3?

一笑奈何 提交于 2019-11-30 09:27:26

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!