var info models.HelpRelation
        // 关系
        err = p.DB().Debug().Model(&info).
            Where(models.HelpRelationColumns.UserID, p.MyId()).
            Where(models.HelpRelationColumns.IDCardID, param.IdCardID).
            Attrs(models.HelpRelation{
                IDCardID:       param.IdCardID,
                UserID:         p.MyId(),
                RelationStatus: models.HelpRelationStatusHelping,
                CreatedUserID:  p.MyId(),
            }).
            FirstOrCreate(&info).Error
        if err != nil {
            exce.ThrowSys(exce.CodeRequestError, err.Error())
        }

        info.IDCardID = param.IdCardID
        info.UserID = p.MyId()
        info.RelationStatus = models.HelpRelationStatusHelping
        err = p.DB().Debug().Save(&info).Error
        if err != nil {
            exce.ThrowSys(exce.CodeRequestError, err.Error())
        }

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: xgpc

在info.id = 2的时候调用该代码的Save过程中 执行了一次 INSERT, 以下是log

2024/01/05 18:21:28 E:/work/gitlab/civil-admin/civil-admin-service-code/internal/api/help/basics/set.go:108 [186.069ms] [rows:0] SELECT * FROM help_relation WHERE user_id = 352 AND id_card_id = 384 ORDER BY help_relation.id LIMIT 1

2024/01/05 18:21:28 E:/work/gitlab/civil-admin/civil-admin-service-code/internal/api/help/basics/set.go:108 [244.806ms] [rows:1] INSERT INTO help_relation (id_card_id,user_id,created_at,created_user_id,relation_status) VALUES (384,352,1704450088,352,1)

2024/01/05 18:21:43 E:/work/gitlab/civil-admin/civil-admin-service-code/internal/api/help/basics/set.go:116 [252.814ms] [rows:0] UPDATE help_relation SET id_card_id=384,user_id=352,created_at=1704450088,created_user_id=352,relation_status=1 WHERE id = 2

2024/01/05 18:21:43 E:/work/gitlab/civil-admin/civil-admin-service-code/internal/api/help/basics/set.go:116 Error 1062 (23000): Duplicate entry '2' for key 'help_relation.PRIMARY' [244.736ms] [rows:0] INSERT INTO help_relation (id_card_id,user_id,created_at,created_user_id,relation_status,id) VALUES (384,352,1704450088,352,1,2)

Comment From: xgpc

这是我的sql信息

/**sql* CREATE TABLE help_relation ( id int unsigned NOT NULL AUTO_INCREMENT, id_card_id int unsigned NOT NULL, user_id int unsigned DEFAULT NULL, created_at bigint DEFAULT NULL, created_user_id int unsigned DEFAULT NULL COMMENT '创建人(预防管理员添加)', relation_status int NOT NULL DEFAULT '1' COMMENT '帮扶状态:[1帮扶中, 2已解绑]', PRIMARY KEY (id), UNIQUE KEY help_relation_pk2 (id), KEY help_relation_id_index (id), KEY help_relation_id_card_details_id_card_id_fk (id_card_id), CONSTRAINT help_relation_id_card_details_id_card_id_fk FOREIGN KEY (id_card_id) REFERENCES id_card_details (id_card_id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='帮扶关系' sql***/ // HelpRelation type HelpRelation struct { ID uint32 gorm:"primaryKey;column:id" json:"id" IDCardID uint32 gorm:"column:id_card_id" json:"id_card_id" UserID uint32 gorm:"column:user_id" json:"user_id" CreatedAt int64 gorm:"column:created_at" json:"created_at" CreatedUserID uint32 gorm:"column:created_user_id" json:"created_user_id" RelationStatus int gorm:"column:relation_status" json:"relation_status" }

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