views:

194

answers:

1

What's the best way to add foreign keys to my existing tables in Rails with an underlying MySQL database? clearly the solution should be done in a migration, as I want this versioned. Otherwise I'd create the constraints myself.

I can't seem to find one, conducive response to they above. Again, the tables have already been created with previous migrations. I'm just going back now and adding referential integrity wherever it's applicable.

+3  A: 

Foreigner works nicely for managing foreign keys.

Alternatively, you can just use the execute method to issue ALTER statements within your new migrations.

Dave Pirotte