向列组合添加唯一约束的迁移 [英] A migration to add unique constraint to a combination of columns

查看:143
本文介绍了向列组合添加唯一约束的迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的是一种将唯一约束应用于列组合的迁移。

What I need is a migration to apply unique constraint to a combination of columns.

对于Person表,Firstname,LastName和Dob的组合应该是唯一的。

for a Person table a combination of Firstname, LastName and Dob should be unique.

推荐答案

add_index:people,[:firstname,:lastname,:dob],:unique => true

这篇关于向列组合添加唯一约束的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆