CREATE TABLE tests ( id bigint NOT NULL AUTO_INCREMENT, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', user_id bigint NOT NULL DEFAULT '0', entity_id bigint NOT NULL DEFAULT '0', PRIMARY KEY (id), UNIQUE KEYuniq_phone(user_id,entity_id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin COMMENT ='测试'

mysql版本 8.0.21

` tests := []test{ { UserId: 1, EntityId: 1, }, { UserId: 1, EntityId: 2, }, }

if err := cli.Model(&test{}).
    Clauses(clause.OnConflict{
        Columns:   []clause.Column{{Name: "user_id,entity_id"}},
        DoUpdates: clause.AssignmentColumns([]string{"updated_at", "created_at"})}).
    Create(&tests).Error; err != nil {
    log.Println(err)
}

log.Println(tests)

`

第一次运行返回的id是正常的,第二次就不对了。这个有没有什么方法能拿到正确的id gorm版本 gorm.io/driver/mysql v1.0.4 gorm.io/gorm v1.20.12

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 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.io ✨ Search Before Asking

Comment From: li-jin-gou

这个是已知问题,当出现批量创建出现冲突时冲突的数据不会返回主键ID @hzylyq :sob: 这里可以尝试更新gorm版本使用 insert returning 获取主键ID

Comment From: guanhonly

这个是已知问题,当出现批量创建出现冲突时冲突的数据不会返回主键ID @hzylyq 😭 这里可以尝试更新gorm版本使用 insert returning 获取主键ID

你好,请问现在有什么方法能够解决这个问题了吗

Comment From: Jasons0215

这个是已知问题,当出现批量创建出现冲突时冲突的数据不会返回主键ID @hzylyq 😭 这里可以尝试更新gorm版本使用 insert returning 获取主键ID

你好,使用returning还是无法返回主键ID,请问是这么使用吗? if err = db.Debug().Clauses( clause.Returning{Columns: []clause.Column{{Name: "id"}}}, clause.OnConflict{ Columns: []clause.Column{{Name: "trade_unit_id"}, {Name: "time"}, {Name: "pow_plan_type"}}, DoUpdates: clause.AssignmentColumns([]string{"trade_unit_name", "price_area", "declare_type", "user_type", "contract_transfer"}), }).Create(&userMonthDeclare).Error; err != nil { resource.BusinessAlarmSend(fmt.Sprintf("date:%v err:%v 生成用户月度申报失败", zeroTm, err.Error())) return nil, err }