Add a reference column migration in Rails 4

前端 未结 7 1854
时光取名叫无心
时光取名叫无心 2020-11-28 00:07

A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like?

Here i

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 00:46

    Just to document if someone has the same problem...

    In my situation I've been using :uuid fields, and the above answers does not work to my case, because rails 5 are creating a column using :bigint instead :uuid:

    add_reference :uploads, :user, index: true, type: :uuid
    

    Reference: Active Record Postgresql UUID

提交回复
热议问题