且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过迁移向现有索引添加`unique`约束

更新时间:2023-02-03 18:21:02

删除旧索引,并使用新约束再次添加它:

Remove the old index and add it again with the new constraint:

def change
  remove_index :editabilities, [:user_id, :list_id]
  add_index :editabilities, [:user_id, :list_id], unique: true
end