class User < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :user
end
Then I ran: rake db:migrate. I don’t get a “user_id” field/column in my Comment table. I also tried: rake db:drop, rake db:create and rake db:migrate. I’m probably missing a step, any ideas?
You have to define the migration.
when you create the comments model by
rails also generate the migration file in your_appication_root/db/migrate/.
the important row for you is
or you can define it directly by