Search code examples
ruby-on-railspostgresqlforeign-keysdatabase-migration

No PostgreSQL foreign keys after Rails migrations


".references" keyword in Rails migrations does not cause creation of foreign keys in PostgreSQL. How to create them using Rails' means only?


Solution

  • Rails doesn't provide any help with foreign key constraints out of the box.

    The foreigner gem adds support for foreign keys, although you do need to specify them in addition to saying t.references :foo