求解答,使用Gorm,执行sql结果为空并报错panic: invalid transaction

Cherry_Yuan · · 3013 次点击
<a href="/user/fenglangjuxu" title="@fenglangjuxu">@fenglangjuxu</a> 好的 谢谢
#4
更多评论
fenglangjuxu
出售域名 http://letsgo.xin
在panic前面 加个日志 打印出来 当数据为空的时候 err具体是什么 然后对这种err做特殊处理 就是认为是正常的 看了下代码 应该有下面几种 ```golang var ( // ErrRecordNotFound returns a &#34;record not found error&#34;. Occurs only when attempting to query the database with a struct; querying with a slice won&#39;t return this error ErrRecordNotFound = errors.New(&#34;record not found&#34;) // ErrInvalidSQL occurs when you attempt a query with invalid SQL ErrInvalidSQL = errors.New(&#34;invalid SQL&#34;) // ErrInvalidTransaction occurs when you are trying to `Commit` or `Rollback` ErrInvalidTransaction = errors.New(&#34;no valid transaction&#34;) // ErrCantStartTransaction can&#39;t start transaction when you are trying to start one with `Begin` ErrCantStartTransaction = errors.New(&#34;can&#39;t start transaction&#34;) // ErrUnaddressable unaddressable value ErrUnaddressable = errors.New(&#34;using unaddressable value&#34;) ) ```
#1
你好,感谢回复,打印出来的错误是这样的: `2021/10/25 16:09:38 invalid transaction; invalid transaction` 是不是就是`no valid transaction`
#2