The default Rails framework seems not support the foreign keys in database migrations and that’s a big omission. You are bound to deal with raw SQL to add these or end up with complex (and often ugly) code to emulate them.

Recently I found a very nice plug-in that adds foreign keys functionality to the migration classes. The syntax looks native and doesn’t stand out prominently. It is also clever enough to recognize some basic intentions, like ‘user_id’ being a reference to the ‘users’ table etc.

Check their other rails works too. They look handy!