diff --git a/callbacks/create.go b/callbacks/create.go index 10da731f..909d984a 100644 --- a/callbacks/create.go +++ b/callbacks/create.go @@ -353,15 +353,14 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) { } } - onConflict := clause.OnConflict{ - Columns: make([]clause.Column, len(stmt.Schema.PrimaryFieldDBNames)), - DoUpdates: clause.AssignmentColumns(columns), - } + onConflict.DoUpdates = clause.AssignmentColumns(columns) - for idx, field := range stmt.Schema.PrimaryFields { - onConflict.Columns[idx] = clause.Column{Name: field.DBName} + // use primary fields as default OnConflict columns + if len(onConflict.Columns) == 0 { + for _, field := range stmt.Schema.PrimaryFields { + onConflict.Columns = append(onConflict.Columns, clause.Column{Name: field.DBName}) + } } - stmt.AddClause(onConflict) } }