gpt4 book ai didi

php - 升级到laravel 5.3后无法工作的分组

转载 作者:行者123 更新时间:2023-12-04 16:31:03 25 4
gpt4 key购买 nike

这是在laravel 5.2上运行的代码

$menus = CmsMenuItem::groupBy('menu_id')->get();

但现在它抛出错误

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'convertifier_cms.cms_menu_items.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 'cms_menu_items' group by 'menu_id')



我也尝试过
 `strict => false` 

在database.php中,但没有效果

最佳答案

试试这个进行数据库配置。

 'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],

并以这种方式使用查询
$menus =DB::table('cms_menu_item')
->select('*')
->groupBy('menu_id')
->get();

关于php - 升级到laravel 5.3后无法工作的分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39344897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com