Add a reference column migration in Rails 5

31,442

As with prior versions of Rails, you may use the following command to create the migration:

rails g migration AddUserToUploads user:references

Unlike prior versions of Rails, the migration looks like:

class AddUserToUploads < ActiveRecord::Migration[5.0]
  def change
    add_reference :uploads, :user, foreign_key: true
  end
end
Share:
31,442
kkurian
Author by

kkurian

former Member of the Technical Staff at Massachusetts Institute of Technology's Lincoln Laboratory; startup experience in both technical and non-technical roles; Ivy League graduate-level computer science degree; and more...

Updated on February 11, 2021

Comments