Laravel Syntax error or access violation: 1055 ‘***’ isn’t in GROUP BY

After laravel 5.3, MySQL strict mode is enabled by default ( strict )
in MySQL strict mode, and only is enabled_ FULL_ GROUP_ If the
group by field does not appear in the select statement, an error will be reported. If the strict mode is turned off, no error will be reported

The demo is as follows

public static function orders($phase) { return self::select(DB::raw("SUM(orders) as orders"),"type","users_id","name") ->groupBy("type","name") ->where("phase",$phase) ->get(); }

The following errors will appear. Of course, the contents of the * sign are different

Syntax error or access violation: 1055 '***' isn't in GROUP BY


laravel the reason for the above error is sql_ For problems caused by mode setting, modify strict = > in config/database. PHP configuration file; False to turn off strict mode:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, ],

Similar Posts: