在插入新数据时如果字段是 UNIQUE INDEX 并且已有同样的值,则会报 Duplicate Entry (mysql)错误。是否可以在 errors.go 文件里加一个变量用于表示这个错误?
文档里有 Upsert, OnConflict 相关的内容,但是我希望能得到 duplicate entry 错误类型,然后由我自己的 go 代码做一些额外的操作,例如清理/删除磁盘上的相关文件。 https://gorm.io/docs/create.html#Upsert-On-Conflict
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: Jimwi
在代码中怎么判断 Duplicate Entry error ?
Comment From: Heliner
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the
Questiontemplate, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨在代码中怎么判断 Duplicate Entry error ? #5144
@Jimwi https://github.com/go-gorm/gorm/issues/5144#issuecomment-1065896567 this hava an temporarily solution , but i'm not sure ,this solution will cover all case.