php - Laravel Eloquent Group通过抛出 SQL 错误
问题描述
当我手动运行以下 SQL 时,我得到了没有错误的预期结果
select * from `crawl_results`
where `user_id` = 1 and `website_id` = 1
and `item_state` != 'OK' group by `destination_url`
limit 30 offset 0
但是,当我在 Eloquent 中运行它时...
self::where('user_id', Auth::id())
->where('website_id', $scanID)
->where('item_state', '!=' , 'OK')
->groupby('destination_url')->paginate(30)
它会产生此错误:
SQLSTATE[42000]:语法错误或访问冲突:1055 'link_checker.crawl_results.id'不在 GROUP BY 中(SQL:select * from
crawl_results
whereuser_id
= 1 andwebsite_id
= 1 anditem_state
!= OK group bydestination_url
limit 30 offset 0)
不确定抽象背后发生了什么以产生该错误?
解决方案
您应该转到 config\database.php并将strict更改为false
'mysql' => [
...
'strict' => false,
...
]
推荐阅读
- actframework - actframework 无法使用 $.merge 保存在数据库中
- excel - 从 excel 电子表格复制到 Blazor 应用程序
- xml - SSIS XML 源组件
- tensorflow - 如何在 TensorFlow Object Detection API 中使用fine_tune_checkpoint
- testing - 如何对依赖于 Web 应用程序警报通知 ID 的移动应用程序进行性能测试?
- javascript - 如何在 React 动态 JSX 中从一个 div 到另一个 div 绘制箭头?
- python - Jupyter notebook 在使用 MinMaxScalar 或 StandardScalar 时出错?
- spring - SpringBoot Logback 配置错误 - 空或空模式
- hotchocolate - hotchocolate:如何在 Errors[] 数组中引发多个错误
- c++ - 在 C++ 中按名称从页面源获取页面信息