laravel 报错this is incompatible with sql_mode=only_full_group_by

laravel操作数据库的时候有时候会发现如下错误:

SQLSTATE[42000]: Syntax error or access violation: 
1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'vuespa.messages.user_id' which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by (SQL: select type,user_id,see,count(*) as count from `messages` group by `type` having `see` = 0 and `user_id` = 1)

这是因为laravel mysql数据库开启了严格模式,导致很多mysql语句可能会报错,我们可以将其关闭即可

找到config/database.php,修改'strict' => true,改为false即可


你可能感兴趣的:(laravel 报错this is incompatible with sql_mode=only_full_group_by)