laravel模型使用groupby函数报错 | laravel china 社区-大发黄金版app下载
laravel版本:7.0
mysql版本:5.7.26
php 7.2
sqlstate[42000]: syntax error or access violation: 1055 expression #1 of select list is not in group by clause and contains nonaggregated column 'tp_6.article.id' which is not functionally dependent on columns in group by clause; this is incompatible with sql_mode=only_full_group_by (sql: select * from article group by user_id)- 产生原因:- 由于 - mysql默认开启严格模式,当- select字段比- group by使用到的字段多的时候,会报错。
- 大发黄金版app下载的解决方案:- 在laravel的 - config/database.php中设置- strict为- false,关闭严格模式,如下图: 
ps : 关闭严格模式会有一些其他的影响,比如varchar字符长度超过了指定的长度,会截取到指定长度,而不会报错等
参考博客:
本作品采用《cc 协议》,转载必须注明作者和本文链接
                                
                                
                                    emin
                                
                            
                        
                     
 
推荐文章: