A migration to add unique constraint to a combination of columns

前端 未结 6 445
你的背包
你的背包 2020-11-29 17:40

What I need is a migration to apply unique constraint to a combination of columns. i.e. for a people table, a combination of first_name, last

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 18:16

    Hi You may add unique index in your migration to the columns for example

    add_index(:accounts, [:branch_id, :party_id], :unique => true)
    

    or separate unique indexes for each column

提交回复
热议问题