开发者

Add foreign key constraints to existing tables in Ruby on Rails (MySQL)

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 th开发者_高级运维ey 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.


Foreigner works nicely for managing foreign keys.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜