Rails 3 migrations: Adding reference column?

PlankTon picture PlankTon · Feb 10, 2011 · Viewed 114k times · Source

If I create a new rails 3 migration with (for example)

rails g migration tester title:tester user:references

, everything works fine...however if I add a column with something along the lines of:

rails g migration add_user_to_tester user:references

the reference field is not recognised. In short, the question is: how do I add a referencing column to a rails migration from the command line?

Answer

Paulo Fidalgo picture Paulo Fidalgo · May 3, 2013

If you are using the Rails 4.x you can now generate migrations with references, like this:

rails generate migration AddUserRefToProducts user:references

like you can see on rails guides