go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.56k stars 3.91k forks source link

gorm.DB.Clauses(clause.OnConflict{UpdateAll: true}) do not wok when using CreateInBatches #7190

Open tuhaolam opened 1 week ago

tuhaolam commented 1 week ago

1、问题: gorm.DB.Clauses(clause.OnConflict{UpdateAll: true})在执行CreateInBatches时不生效,反复出现同样的报错信息,并且更新失败,表存在唯一索引idx_ns_domain_path,由nsdomain_path字段构成:

2024-09-05 22:37:00.413 ERROR   demo/demo_nodes.go:215  Error 1062: Duplicate entry 'demotest-newApp4cat' for key 'idx_ns_domain_path'
2024-09-05 22:37:00.662 ERROR   demo/t_demo_demo_nodes.gen.go:50    failed to exec BatchInsertdemoNode: Error 1062: Duplicate entry 'demotest-newApp4cat' for key 'idx_ns_domain_path'
2024-09-05 22:37:00.662 ERROR   demo/demo_nodes.go:215  Error 1062: Duplicate entry 'demotest-newApp4cat' for key 'idx_ns_domain_path'
2024-09-05 22:37:00.896 ERROR   demo/t_demo_demo_nodes.gen.go:50    failed to exec BatchInsertdemoNode: Error 1062: Duplicate entry 'demotest-newApp4cat' for key 'idx_ns_domain_path'

2、环境

    gorm.io/driver/mysql v1.3.2
    gorm.io/gorm v1.25.8
github-actions[bot] commented 1 week ago

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 Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking