Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable only_full_group_by option in Laravel

I am new to laravel and I am having an issue with DB problem.

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.

However, when I make a request through postman, it gives me the error saying this is incompatible with sql_mode=only_full_group_by.

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.

Thank you.

SQL using toSql()

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;
like image 279
smchae Avatar asked Jan 08 '18 06:01

smchae


2 Answers

To answer the original question, if you want to disable this in Laravel you have to change the 'strict' value to false in your database configuration in config/database.php.

'connections' => [
...

    'mysql' => [
    ...
        'strict' => false,
        ...

    ],

]
like image 138
Brian Avatar answered Sep 24 '22 01:09

Brian


Add this modes to config/database.php

'mysql' => [
 ...
        'modes' => [
            'STRICT_ALL_TABLES',
        ],
],

If you set 'strict' => true. Some sql exception will not throw like sql data integrity exception.

like image 28
thebvg1ne-zoren Avatar answered Sep 25 '22 01:09

thebvg1ne-zoren