OnConflict UpdateAll includes fields that specified default values via tag

This commit is contained in:
Jinzhu 2021-01-04 15:13:56 +08:00
parent 9b8d3b3a0f
commit 60b769c2c8
1 changed files with 1 additions and 1 deletions

View File

@ -337,7 +337,7 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) {
columns := make([]string, 0, len(values.Columns)-1) columns := make([]string, 0, len(values.Columns)-1)
for _, column := range values.Columns { for _, column := range values.Columns {
if field := stmt.Schema.LookUpField(column.Name); field != nil { if field := stmt.Schema.LookUpField(column.Name); field != nil {
if !field.PrimaryKey && !field.HasDefaultValue && field.AutoCreateTime == 0 { if !field.PrimaryKey && (!field.HasDefaultValue || field.DefaultValueInterface != nil) && field.AutoCreateTime == 0 {
columns = append(columns, column.Name) columns = append(columns, column.Name)
} }
} }