laravel,mysql5.6数据分组报错 isn’t in GROUP BY

作者: JONE 分类: 编程 发布时间: 2020-07-22 10:44
Illuminate \ Database \ QueryException (42000)
SQLSTATE[42000]: Syntax error or access violation: 1055 ‘share_com.users.name’ isn’t in GROUP BY (SQL: select user_id, SUM(money) as count_money, users.name, users.avatar from `dy_user_daily_incomes` left join `users` on `users`.`id` = `dy_user_daily_incomes`.`user_id` where `dy_user_daily_incomes`.`date` = 20200721 and `dy_user_daily_incomes`.`deleted_at` is null group by `dy_user_daily_incomes`.`user_id` order by `count_money` desc limit 50)

在Laravel中运行原生MySQL时经常遇到分组group by的报错,这就是laravel的严格模式搞的鬼。。。关闭了严格模式就好

在 config 目录下 database.php 文件中找到你所使用的MySQL数据库修改 strict 属性为false

‘strict’ => true,

原链接:https://www.jianshu.com/p/1a0c5885d9e7