gpt4 book ai didi

php - 如何解决 laravel eloquent 中与 sql_mode=only_full_group_by 不兼容的问题?

转载 作者:IT王子 更新时间:2023-10-28 23:52:48 25 4
gpt4 key购买 nike

我的 laravel Eloquent 是这样的:

$products = Product::where('status', 1)
->where('stock', '>', 0)
->where('category_id', '=', $category_id)
->groupBy('store_id')
->orderBy('updated_at', 'desc')
->take(4)
->get();

执行时出现如下错误:

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'myshop.products.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 products where status = 1 and stock > 0 and category_id = 5 group by store_id order by updated_at desc limit 4)

我该如何解决?

最佳答案

我有一个类似的问题,通过在数据库连接设置中禁用 mysql 严格模式来解决它。

'connections' => [
'mysql' => [
// Behave like MySQL 5.6
'strict' => false,

// Behave like MySQL 5.7
'strict' => true,
]
]

您可以在 this blog post by Matt Stauffer 中找到更多配置设置

关于php - 如何解决 laravel eloquent 中与 sql_mode=only_full_group_by 不兼容的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776758/

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