Rails 4.2 newly supports adding and removing foreign keys (in migrations), like:
# add a foreign key to `articles.author_id` referencing `authors.id`
add_foreign_key :articles, :authors
What I don't understand is: How is this
add_foreign_key :articles, :authors
different from this:
add_column :articles, :author_id, :integer
Thank you for any clarification!
The difference is that line:
will actually generates this:
While this:
will generate:
Both are different because
add_foreign_key
will add just a foreign key constraint, whileadd_column
adds a column not a constraint.