Group not working - Laravel

I cannot run this simple query in Laravel 5.3

$top_performers = DB::table('pom_votes')
        ->groupBy('performer_id')
        ->get();

This gives me:

SQLSTATE[42000]: Syntax error or access violation: 1055 'assessment_system.pom_votes.id' isn't in GROUP BY (SQL: select * from `pom_votes` group by `performer_id`)

However, if I copy the raw request from an error and run directly in PhpMyAdmin, it works fine.

I already checked this:

https://laravel.com/docs/5.3/queries#ordering-grouping-limit-and-offset

Any help would be applied.

Thanks,

Parth vora

+13
source share
4 answers

Edit config/database.phpapplication file configurationconfig/database.php

In the array, mysqlset strict => falseto disable MySQL strict mode

+48
source

, , MySQL 5.7. 5+. , GROUP BY , , , SQL99 ( ).

MySQL.

MySQL-, GROUP BY

+7

/database.php

mysql strict => false, mod MySQL

sudo nano/etc/mysql/mysql.cnf

[mysqld] sql_mode = NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION

0

If you are mistakenly using strict mode, you cannot use other strict functions to correct this error. Go to Illuminate \ Database \ Connectors \ MySqlConnector.php and change the function as shown below:

protected function strictMode() {
return "set session
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY
_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'";
}

replace the function with this.

-one
source

Source: https://habr.com/ru/post/1013942/


All Articles