当进去表的update操作的时候

报错说,不正确的表名

查看日志发现sql语句里面没有表名

 

需要在update操作的时候,Model()方法指定好要更新的表struct类型

官方的注释

// update all users's name to `hello`
   db.Model(&User{}).Update("name", "hello")
   // if user's primary key is non-blank, will use it as condition, then will only update the user's name to `hello`
   db.Model(&user).Update("name", "hello")

.Model方法,参数必须这样的,&User{} 这种结构体指针 ,user这个是结构体或者指针的情况下,也要再&取一下地址

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-08-10
猜你喜欢
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-01-04
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案