Ruby-on-rails – Rails 3 migrations: Adding reference column

activerecordmigrationruby-on-rails

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?

Best Answer

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