我如何解决在laravel雄辩中与sql_mode = only_full_group_by不兼容的问题? [英] How can I solve incompatible with sql_mode=only_full_group_by in laravel eloquent?

查看:241
本文介绍了我如何解决在laravel雄辩中与sql_mode = only_full_group_by不兼容的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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 where status = 1 and stock > 0 and category_id = 5 group by store_id order by updated_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,
    ]
]

您可以在 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆