我正在运行 activerecord 3.0.0beta。我知道您可以使用外键创建列,例如
create_table "my_things" do |t|
t.reference "other_thing_id"
end
但我忘了,只是把它变成了一个普通的整数。现在,我添加了一个类似的迁移
execute("alter table my_things add constraint fk_other_thing foreign key (other_thing_id) references other_things(id)")
效果很好,但我没有在 schema.rb 中看到任何等效项(我希望有 t.reference
),所以如果我执行模式加载,我不会得到我的约束。解决该问题的最佳方法是什么?
最佳答案
您可能对 foreigner 感兴趣.它可以帮助您在迁移中创建外键,并将它们添加到您的 schema.rb。
关于ruby - activerecord 迁移中的外键与 schema.rb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3105631/