-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
db.Clauses(clause.OnConflict{UpdateAll: true}).Create(users)` 导致主键不连续 #7257
Comments
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 |
因为按照你描述的,你插入过程中发生了Conflict(不然就应该是三条数据)。 |
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 |
我看了一下,好像是MYSQL insert on duplicate key ,对于及更新又插入会统一计算ID自增,所以会导致主键不连续,不是gorm的问题,gorm底层也是insert on duplicate key |
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 |
本来这件事就跟gorm没什么关系,gorm更多的只是一个数据库调用框架(SQL builder),具体的相关逻辑实际上还是要看数据库引擎的实现。这也是为什么上面提到让你去看看数据库的MVCC逻辑。 |
insert into users values (1,"users","test","2024-10-27",null); |
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 |
因为你是 |
抱歉,我不知道您这个我该怎么测,我是一个菜鸟 |
非常感谢您的例子,学习到了,网络上没有这种例子,真是给我这个菜鸟上了一课 |
我之前出现的问题是干业务的时候出现的,业务表中没有唯一索引,对于批量进行insert 的时候会出现主键不连续的问题,已经解决,https://byzer.csdn.net/6571542eb8e5f01e1e4437f3.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTg0MjU2OSwiZXhwIjoxNzMwNjMzNjQwLCJpYXQiOjE3MzAwMjg4NDAsInVzZXJuYW1lIjoibTBfNTI4OTgzODkifQ.0kIMch5-3BcjnbqKvwpL0pat1jRMm8giZCLyYx0RgGQ |
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 |
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 |
使用这段代码的时候,假如数据库有一行数据,主键ID为1,执行create会又插入又更新,这时候数据库的数据会变成两行,但是在插入下一条数据的时候,主键ID会变成4,而不是3,应该是create执行的时候出现了问题,请问是如何造成的
The text was updated successfully, but these errors were encountered: