postgresql update duplicate key value violates unique constraint

问题

使用SQL update 语句,出现 duplicate key value violates unique constraint 错误

解决方法

//把
ModuleID           string            `json:"module_id" binding:"required" gorm:"unique"`
//改成
ModuleID           string            `json:"module_id" binding:"required" gorm:"uniqueIndex"``

automigrate 无法生效,需要删除数据库volume重启

posted @ 2022-08-26 22:15  略略略——  阅读(192)  评论(0编辑  收藏  举报