user24359
user24359

Reputation:

foreign keys in activerecord migrations vs. schema.rb

I'm running activerecord 3.0.0beta. I know you can create columns with foreign keys like

create_table "my_things" do |t|
  t.reference "other_thing_id"
end

but I forgot and just made it a plain integer. Now, I've added a migration like

execute("alter table my_things add constraint fk_other_thing foreign key (other_thing_id) references other_things(id)")

That worked fine, but I don't see anything equivalent appear in schema.rb (I was hoping for t.reference), so if I did a schema load, I wouldn't get my constraint. What's the best way to fix that?

Upvotes: 2

Views: 1361

Answers (1)

Tomas Markauskas
Tomas Markauskas

Reputation: 11596

You might be interested in foreigner. It helps you create foreign keys in your migrations and also adds them to your schema.rb.

Upvotes: 2

Related Questions