Reputation: 289
I have two models Artist
and Painting
.
I added the following migration and executed rake db:migrate
class AddArtistReferenceToPaintings < ActiveRecord::Migration
self.up do
change_table :paintings do |t|
t.references :artist
end
end
end
This doesn't change anything in the database. What am I doing wrong?
Upvotes: 0
Views: 556
Reputation: 5961
Seems correct .
Did you already run this migration and added this latter ? If yes then create new one OR delete version from schema_migrations .
Way : To add a foreign key column
change_table(:suppliers) do |t|
t.references :company
end
It creates a company_id(integer) column
To add a polymorphic foreign key column
change_table(:suppliers) do |t|
t.belongs_to :company, :polymorphic => true
end
It creates company_type(varchar) and company_id(integer) columns .
For further detail refer the link.
Upvotes: 1
Reputation: 19398
Try
t.belongs_to :artist
instead
t.references :artist
But your variant should work too, if you test in irb console. Run 'reload' to update.
Upvotes: 1