0

I want to create tables with foreign key through my migration script.

create_table :posts do |t|
  t.string :title
end

create_table :comments do |t|
  t.references :post
end

after rake db:migrate, comments was not referred by post through id.

How to create this in rails-2.2.3?

Achaius
  • 5,904
  • 21
  • 65
  • 122

1 Answers1

0

You can create migration as normal table schema and use :primary_key option for belongs_to for broader support of legacy schemas and those using a separate foreign key:

belongs_to :posts, :foreign_key => 'post_id'

Babasaheb Gosavi
  • 7,735
  • 1
  • 14
  • 14