向 Ruby on Rails (MySQL) 中的现有表添加外键约束
使用底层 MySQL 数据库向 Rails 中的现有表添加外键的最佳方法是什么?显然,解决方案应该在迁移中完成,因为我想要这个版本。否则我会自己创造约束。
我似乎找不到对上述问题有利的回应。同样,这些表已经通过之前的迁移创建了。我现在要回去并在适用的地方添加引用完整性。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Foreigner 非常适合管理外键。
或者,您可以仅使用execute 方法在新迁移中发出ALTER 语句。
Foreigner works nicely for managing foreign keys.
Alternatively, you can just use the execute method to issue ALTER statements within your new migrations.