我如何解决在laravel雄辩中与sql_mode = only_full_group_by不兼容的问题? [英] How can I solve incompatible with sql_mode=only_full_group_by in laravel eloquent?
问题描述
我的laravel雄辩是这样的:
My laravel eloquent is like this :
$products = Product::where('status', 1)
->where('stock', '>', 0)
->where('category_id', '=', $category_id)
->groupBy('store_id')
->orderBy('updated_at', 'desc')
->take(4)
->get();
执行时,会出现这样的错误:
When executed, there exist error like this :
SQLSTATE [42000]:语法错误或访问冲突:1055表达式#1 SELECT列表的内容不在GROUP BY子句中,并且包含非聚合的 列"myshop.products.id"在功能上不依赖于 GROUP BY子句中的列;这与 sql_mode = only_full_group_by(SQL:从
products
选择*status
= 1和stock
> 0和category_id
= 5由store_id
分组 按updated_at
desc限制4排序)
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
wherestatus
= 1 andstock
> 0 andcategory_id
= 5 group bystore_id
order byupdated_at
desc limit 4)
我该如何解决?
推荐答案
我遇到了类似的问题,并通过在数据库连接设置中禁用mysql严格模式来解决了这个问题.
I had a similar Problem and solved it by disabling mysql strict mode in the database connection setting.
'connections' => [
'mysql' => [
// Behave like MySQL 5.6
'strict' => false,
// Behave like MySQL 5.7
'strict' => true,
]
]
您可以在 查看全文