Hacker News new | ask | show | jobs
by nicolasMLV 2794 days ago
Rails uses foreign keys by default, usually I generate a migration file with `rails generate migration AddThisToThing this:references`

Then this line is generated `add_reference :things, :this, foreign_key: true`

and then we call the migration, and there is the foreign key.

1 comments

Is it not more accurate to say "by default rails generates migrations with the foreign key argument set to a non default value of true"?

By default the relationship constructors do not create foreign keys, if they did it would be redundant to include it in the generated output surely? At least that's what the docs seem to say.