GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
After successfully updating data using Updates, RowsAffected returns 0
db := mysql.DB.Model(&User{}).Where("deleted = 0 and id = ?", id).Updates(map[string]interface{}{"updated_time": time.Now()})
db.RowsAffected
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: gg1229505432
I try this func, I made it. this is func:
type User struct { ID uint Name string UpdatedTime time.Time
json:"updated_time"}func main() { dsn := "root:pwd@tcp(localhost:3306)/meeting_as?charset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database") } fmt.Println("Database connected successfully!") err = db.AutoMigrate(&User{}) if err != nil { panic("failed to migrate database") } tx := db.Model(&User{}).Where("id = ?", 2).Updates(map[string]interface{}{"updated_time": time.Now()}) affected := tx.RowsAffected fmt.Println(affected) }
Comment From: gg1229505432
maybe your column name is wrong ( updated_time but update_time ) mybe your column type is not time.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: Fantomo
I try this func, I made it. this is func:
type User struct { ID uint Name string UpdatedTime time.Time
json:"updated_time"}func main() { dsn := "root:pwd@tcp(localhost:3306)/meeting_as?charset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database") } fmt.Println("Database connected successfully!") err = db.AutoMigrate(&User{}) if err != nil { panic("failed to migrate database") } tx := db.Model(&User{}).Where("id = ?", 2).Updates(map[string]interface{}{"updated_time": time.Now()}) affected := tx.RowsAffected fmt.Println(affected) }
Thanks, the problem has been solved.
Comment From: Fantomo
maybe your column name is wrong ( updated_time but update_time ) mybe your column type is not time.Time
Thanks, the problem has been solved.
Comment From: Fantomo
not a bug