参考Rails 4.2
add_foreign_key支持:
# add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles,:authors
如何创建可空的外键约束,以允许这种情况,其中的article.author_id有时可以为空?