【问题标题】:Two columns in Rails foreign key migrationsRails 外键迁移中的两列
【发布时间】:2018-11-04 12:26:59
【问题描述】:

问候!

我可以通过这种方式在 Rails 迁移中为表添加外键:

add_foreign_key :teachers, :departamentos, name: "teachers_departamento_id", 
column: :codigo_departamento, primary_key: :codigo

但是,如何将两列添加到外键中?

谢谢。

【问题讨论】:

  • 你能解释一下你想通过这样做实现什么功能吗?

标签: ruby-on-rails activerecord migration


【解决方案1】:

你可以这样做

add_index :table, ["column1", "column2"], :unique => true

基于来自 SO 的 question

【讨论】:

  • 感谢回答。仅添加索引但不添加外键。
猜你喜欢
  • 2019-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-03
  • 1970-01-01
  • 2011-03-19
相关资源
最近更新 更多