如何在Laravel中禁用only_full_group_by选项 [英] How to disable only_full_group_by option in Laravel
问题描述
我是laravel的新手,但是我遇到数据库问题.
I am new to laravel and I am having an issue with DB problem.
我已通过编辑/etc/mysql/my.cnf
文件禁用了"only_full_group_by" sql_mode.然后,我使用SELECT @@GLOBAL.sql_mode;
和SELECT @@SESSION.sql_mode;
检查了sql_mode
的全局和会话,并确认sql_mode
不再具有only_full_group_by
.
I have disabled 'only_full_group_by' sql_mode by editing /etc/mysql/my.cnf
file. And I checked sql_mode
for both global and session using SELECT @@GLOBAL.sql_mode;
and SELECT @@SESSION.sql_mode;
and confirmed that sql_mode
no longer has only_full_group_by
.
但是,当我通过邮递员发出请求时,它会显示错误消息this is incompatible with sql_mode=only_full_group_by
.
However, when I make a request through postman, it gives me the error saying this is incompatible with sql_mode=only_full_group_by
.
我很困惑.即使更改了sql_mode
,为什么仍然出现此错误?我在做错什么吗?
I am so confused. Why do I get this error even after I changed sql_mode
? Am I doing something wrong?
任何建议或建议都将不胜感激.
Any suggestion or advice would be appreciated.
谢谢.
使用toSql()的SQL
select A.*
from `A`
inner join `B` on `A`.`id` = `B`.`a_id`
inner join `C` on `C`.`id` = `B`.`c_id`
group by `A`.`id` having COUNT(A.id) > 0;
推荐答案
这是错误的处理方式.而不是关闭only_full_group_by
模式,您应该修复查询以使其不会破坏MySQL:
This is the wrong way of going about this. Rather than turning off only_full_group_by
mode, you should be fixing your query so that it doesn't break MySQL:
SELECT a1.*
FROM A a1
INNER JOIN
(
SELECT A.id
FROM A
INNER JOIN B
ON A.id = B.a_id
INNER JOIN C
ON C.id = B.c_id
GROUP BY A.id
HAVING COUNT(A.id) > 0
) a2
ON a1.id = a2.id;
我不知道为什么您关闭严格模式的尝试失败了,但是无论如何您都不应依赖它.
I don't know why your attempts to turn off strict mode failed, but you should not be relying on it in any case.
这篇关于如何在Laravel中禁用only_full_group_by选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!