解決laravel出現Syntax error or access violation: 1055 ‘***‘ isn‘t in GROUP BY
laravel 5.3 以後預設開啟 mysql嚴格模式(strict
)
在mysql在嚴格模式下, 並且開啟了ONLY_FULL_GROUP_BY的情況下,
group by 的欄位沒有出現在 select 的語句中會報錯.關閉了嚴格模式就不會報錯.
如下Demo
複製程式碼
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();
}
會出現如下錯誤,當然*號內的內容是不同的
複製程式碼
Syntax error or access violation: 1055 '***' isn't in GROUP BY
解決辦法
laravel
出現上述錯誤是sql_mode
設定導致的問題,修改config/database.php
配置檔案的strict => false
即可關閉了嚴格模式:
複製程式碼
'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,
],
相關文章
- 執行遷移檔案報錯: Syntax error or access violation: 1166 ...Error
- [報錯:字元太長] SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key was t oo long;字元SQLError
- Laravel5.4 資料庫遷移錯誤 SQLSTATE [42000] Syntax error or access violation 1071Laravel資料庫SQLError
- Laravel 8使用 佇列任務出現 「 syntax error, unexpected ')' 」錯誤解決Laravel佇列Error
- 執行maven專案出現Error:java: JDK isn‘t specified for module ‘XXX‘MavenErrorJavaJDK
- pecl PHP Parse error: syntax error, unexpected 'new' (T_NEW) 以及 XML缺失解決辦法PHPErrorXML
- win10系統提示access violation at address出錯的解決方法Win10
- 如何解決"Parse error: syntax error"Error
- 帝國CMS提示parse error syntax error的解決方法Error
- MySQL5.7 group by新特性報錯1055的解決辦法MySql
- 配置NDK syntax error: unexpected end of file 解決Error
- idea出現Error:Maven Resources Compiler: Maven project configuration required for module 'market' isn't available.IdeaErrorMavenCompileProjectUIAI
- 萬能方法解決——You have an error in your SQL syntaxErrorSQL
- syntax error near unexpected token `問題的解決Error
- wamp出現You don’t have permission to access/on this server提示Server
- 帝國CMS安裝時出現You have an error in your SQL syntax錯誤程式碼的解決方法ErrorSQL
- [筆記].痛哉!!!Error: Can't access JTAG chain, Error: Operation failed筆記ErrorAI
- laravel 解決 mysql only_full_group_by 問題LaravelMySql
- 如何解決"You have an error in your SQL syntax"ErrorSQL
- ArchLinux出現ACPI ERROR的解決方法LinuxError
- MYSQL解決error: 'Access denied for user 'root'@'localhost' (using password:MySqlErrorlocalhost
- mysql ERROR 1045 (28000): Access denied for user解決方法MySqlError
- 解決錯誤:ASP.NET Error: Failed to access IIS metabaseASP.NETErrorAI
- eclipse 引入外部js檔案報Syntax error on token 錯解決方案EclipseJSError
- 解決Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'MySqlErrorlocalhost
- mac osx Forbidden You don't have permission to access / on this server解決方法MacORBServer
- Linux 5中出現的-bash: syntax error near unexpected token `('錯誤LinuxError
- 登入mysql報ERROR 1045 (28000): Access denied 解決方法MySqlError
- Syntax error, unrecognized expression: li[value=]ErrorZedExpress
- syntax error near unexpected token `Error
- exp tables sh: Syntax error: `(' is not expectedError
- 【shell 】syntax error in conditional expressionErrorExpress
- ORA-29702:error occurred in Cluster Group Service operation錯誤解決Error
- Array and string offset access syntax with curly braces is deprecated
- Delphi常見的執行期Access Violation錯誤分析
- NFS掛載時出現”access denied by server while mounting”的解決方法NFSServerWhile
- Springboot中配置動態sql查詢出現的錯誤syntax error, expect ‘)‘Spring BootSQLError
- Solaris syntax error: unexpected end of fileError