GORM Playground Link

https://github.com/go-gorm/playground/pull/481

Description

` package main

import ( "fmt" "time"

"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"

)

type TT struct { ID int gorm:"not null;primaryKey;comment:id" Name string gorm:"not null;default:'';comment:任务名" UpdateTime time.Time gorm:"not null;default:current_timestamp(3);index:idx_update_time;comment:更新时间" CreateTime time.Time gorm:"not null;default:current_timestamp(3);comment:创建时间" }

func main() { var dsn = "xx:xx@tcp(xx:xx)/test?autocommit=true&charset=utf8mb4,utf8&loc=Local&parseTime=true&writeTimeout=30s&readTimeout=60s&timeout=10s" dbConn, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { fmt.Println(err) return } if err := dbConn.AutoMigrate(&TT{}); err != nil { fmt.Println(err) return } var t = TT{ ID: 1, Name: "a", CreateTime: time.Now(), UpdateTime: time.Now(), } if err = dbConn.Clauses(clause.OnConflict{UpdateAll: true}).Create(&t).Error; err != nil { fmt.Println(err) return } t.UpdateTime = time.Now().Add(10 * time.Second) if err = dbConn.Clauses(clause.OnConflict{UpdateAll: true}).Create(&t).Error; err != nil { fmt.Println(err) return } var t2 TT if err = dbConn.First(&t2).Error; err != nil { fmt.Println(err) return } if t2.UpdateTime.Format("2006-01-02 15:04:05") != t.UpdateTime.Format("2006-01-02 15:04:05") { fmt.Printf("expect %s but %s", t.UpdateTime.Format("2006-01-02 15:04:05"), t2.UpdateTime.Format("2006-01-02 15:04:05")) } } `

数据库中的表结构 CREATE TABLEtts(idbigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',namevarchar(191) NOT NULL DEFAULT '' COMMENT '任务名',update_timedatetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '更新时间',create_timedatetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间', PRIMARY KEY (id), KEYidx_update_time(update_time) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4

结果: Gorm clause.OnConflict{UpdateAll: true}   不会更新 update_time

update_time字段并没有被更新

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

go 1.8 gorm:v1.23.5

Comment From: jinzhu

will update those fields with default tag.