解決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,
],
相關文章
- [報錯:字元太長] 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
- 執行遷移檔案報錯: Syntax error or access violation: 1166 ...Error
- 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
- 萬能方法解決——You have an error in your SQL syntaxErrorSQL
- 帝國CMS安裝時出現You have an error in your SQL syntax錯誤程式碼的解決方法ErrorSQL
- ArchLinux出現ACPI ERROR的解決方法LinuxError
- 如何解決"You have an error in your SQL syntax"ErrorSQL
- eclipse 引入外部js檔案報Syntax error on token 錯解決方案EclipseJSError
- laravel 解決 mysql only_full_group_by 問題LaravelMySql
- 【shell 】syntax error in conditional expressionErrorExpress
- 解決ERROR 1231 (42000): Variable 'time_zone' can'tError
- ORA-29702:error occurred in Cluster Group Service operation錯誤解決Error
- Springboot中配置動態sql查詢出現的錯誤syntax error, expect ‘)‘Spring BootSQLError
- 解決 Jenkins 上 git 出現的 “ERROR: Error fetching remote repo 'origin'” 問題JenkinsGitErrorREM
- Array and string offset access syntax with curly braces is deprecated
- NFS掛載時出現”access denied by server while mounting”的解決方法NFSServerWhile
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated cExpressAI
- Syntax error, unrecognized expression: li[value=]ErrorZedExpress
- Solaris syntax error: unexpected end of fileError
- 解決Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)的方法MySqlErrorlocalhost
- yarn add cross-env 出現 protocol error, symlink 解決方案YarnROSProtocolError
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains 的問題 MySQLExpressAIMySql
- NSIS 官方對安裝包出現 NSIS Error 的解釋與解決方案Error
- Win10系統出現終止程式碼怎麼辦?Win10出現程式碼WDF_VIOLATION的解決方法Win10
- git push出現unpack failed: error Missing tree錯誤的解決方法GitAIError
- 解決 sail composer update 時出現的 Update of laravel/sail failedAILaravel
- access開發精要(5)-合計group by
- Laravel-查詢-ONLY_FULL_GROUP_BY SQL 模式-報錯限制-解決LaravelSQL模式
- Laravel Sail 環境下啟動專案出現: ERROR: Service 'laravel.test' failed to buildLaravelAIErrorUI
- springboot 解決跨域 Access to XMLHttpRequest atSpring Boot跨域XMLHTTP
- Linux安裝mysql出現ERROR! The server quit without updating PID file問題解決LinuxMySqlErrorServerUI