gorm --- Error 1292: Incorrect datetime value: ‘1655178473‘ for column ‘updated_at‘ at row 1

一、报错

  在gorm用map进行更新时,虽然设置了自动更新时间,但是在更新时报错:Error 1292: Incorrect datetime value: ‘1655178473’ for column ‘updated_at’ at row 1

在这里插入图片描述
 
 
表结构为:
在这里插入图片描述
 
实现代码:

func Update(id uint, name,description string) error {
	whereMap := map[string]interface{}{}
	whereMap["name"] = name
	whereMap["description"] = description
	err := repo.db.Model(&entity.Project{}).Where("id = ?", id).Updates(whereMap).Error
	return err
}

 

二、原因

  原因暂时没找到,有大佬知道的可以指教下~ 万分感谢~
 

三、解决

手动更新时间:whereMap["updated_at"] = time.Now()

func (repo ProjectRepo) UpdateProject(id uint, name,description string) error {
	whereMap := map[string]interface{}{}
	whereMap["name"] = name
	whereMap["description"] = description
	whereMap["updated_at"] = time.Now()    //手动更新时间
	err := repo.db.Model(&entity.Project{}).Where("id = ?", id).Updates(whereMap).Error
	return err
}

 
 
有小伙伴知道更好方法的,欢迎留言~ 感谢~


版权声明:本文为my_miuye原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。