Reputation: 1590
I have a migration that I want to make with a reference in my table. I create the reference using this:
create_table :user_events do |t|
t.references :user, :null => false
end
And in my migration, I want to be able to allow the reference to be NULL.
def self.up
change_column :user_events, :user, :integer, :null => true
end
However I keep getting PGError: ERROR: column "user" of relation "user_events" does not exist
. Am I migrating wrong?
Upvotes: 0
Views: 1152
Reputation: 16619
try
def self.up
change_column :user_events do |c|
c.references :user, :integer, :null => true
end
end
Upvotes: 0
Reputation: 1138
It's because your migration creates a column named user_id, referencing the User model.
Upvotes: 1
Reputation: 3965
This should work:
def self.up
change_column :user_events, :user_id, :integer, :null => true
end
Note that the column you're trying to change is called user_id
, not user
Upvotes: 3