Ruby Active Record Associations in Rails Active Record Associations A "Has Many" Migration

silva celso
silva celso
12,039 Points

Assume that a pets table already exists. Here at the command line, generate a migration that will add an owner_id foreig

can not seem to get pass this question,

Assume that a pets table already exists. Here at the command line, generate a migration that will add an owner_id foreign key column to the pets table.

Elita Judjallo
Elita Judjallo
9,946 Points

bin/rails g migration AddOwnerToPets owner_id:integer:index

Its worked for me

1 Answer

jide delano
jide delano
14,184 Points

SInce you are adding a column to an already existing table, you need to generate a new migration with the following:

rails generate migration AddOwner_IdToPets owner_id:integer:index