activerecord迁移与schema.rb中的外键

时间:2010-06-23 21:19:13

标签: ruby activerecord foreign-keys

我正在运行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),所以如果我做了架构加载,我就不会得到我的约束。解决这个问题的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

您可能对foreigner感兴趣。它可以帮助您在迁移中创建外键,并将它们添加到schema.rb。

相关问题