报错信息
2023/03/14 16:19:43 E:/go_project/study/gorm/test.go:95 invalid value, should be pointer to struct or slice
[0.508ms] [rows:0] UPDATE `students` SET `deleted_at`='2023-03-14 08:19:43.224' WHERE city LIKE '%州%' AND `students`.`deleted_at` IS NULL
原因分析:大概是因为test.go文件delete方法中,调用指针问题找到 Where(“id=?”, id).Delete(xxx{}) 可以将里面的 xxx{} 改成 &xxx{} 试试看
对比:
报错代码:
db.Where("city LIKE ?", "%州%").Delete(Student{})
修改后:
db.Where("city LIKE ?", "%州%").Delete(&Student{})