Wednesday, June 21, 2017

[Laravel 5.4][Resolved] QueryException SQLSTATE[42000]: Syntax error or access violation: 1055

What i did is update laravel version from 5.0 to 5.4, found everything works but this sql by query builder.:



By default laravel 5.4 would select all (SELECT * ) if you haven't specific the column name you wanted to select, it causes error.

Solution 1

What you can do is add the column name caused error to your groupBy part:
From :
$data   = DB::table('table_a')->where('userid','=', Auth::user()->id)
                            ->where('species','!=', '')
                            ->where('action','=', 'insert')
                            ->join('table_b', 'table_b.index_id', '=', 'table_a.species')
                            ->join('table_c', 'table_b.table_c', '=', 'table_c.name_id')
                            ->groupBy('table_a.species')
                            ->take(5)->orderBy('table_b.last_edit_timestamp', 'desc')->get();
To
$data  = DB::table('table_a')->where('userid','=', Auth::user()->id)
                            ->where('species','!=', '')
                            ->where('action','=', 'insert')
                            ->join('table_b', 'table_b.index_id', '=', 'table_a.species')
                            ->join('table_c', 'table_b.table_c', '=', 'table_c.name_id')                            ->groupBy('table_a.species','table_b.last_edit_timestamp',"scientific_name","formatted_sciname")
                            ->take(5)->orderBy('table_b.last_edit_timestamp', 'desc')
                            ->select(["scientific_name","formatted_sciname","species"])
                            ->get();

Solution 2 

change default value of strict from true to false, in config/database.php at "mysql"
 'strict' => true


Reference :

https://github.com/barryvdh/laravel-translation-manager/issues/144

No comments :

Post a Comment