Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 CreateInBatches 批量插入时 会返回 Error 1062 (23000): Duplicate entry '2606' for key 'xxx.PRIMARY' #7347

Open
sosososmall opened this issue Jan 20, 2025 · 1 comment
Assignees
Labels
type:question general questions

Comments

@sosososmall
Copy link

sosososmall commented Jan 20, 2025

Your Question

我在程序里大量使用了 db.Table('xxx').CreateInBatches(records, 100),但是在程序运行中有一个定时任务(1天1次)在插入数据时偶尔会出现
Error 1062 (23000): Duplicate entry '2606' for key 'xxx.PRIMARY' 这个错误提示。让我百思不得其解的是大量的 CreateInBatches 调用 ,之前仅有
这一个表在批量插入时会出现这个问题。因为技术原因排查不出问题前天就把无用的主键ID 删除掉了 ,然后昨天和今天另一个表开始出现了同样的问题。请问我应该如何做。MySQL 8.0.32 go 1.20 gorm.io/driver/mysql v1.5.7 gorm.io/gorm v1.25.12

The document you expected this should be explained

Expected answer

@sosososmall sosososmall added the type:question general questions label Jan 20, 2025
@QeelinDarly
Copy link

First, I wanna know if you inserted diff data with the same primary key, that will cause this error. And maybe you can check if there are any parallel issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

3 participants