SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 't.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: SELECT t.* FROM (SELECT * FROM article_video WHERE article_id IN (14536,2321704,2321803,2321804,2321805,2321806) ORDER BY id DESC LIMIT 500) AS t GROUP BY t.article_id ORDER BY t.id DESC LIMIT 6) (View: D:\web\4E\project_test\resources\views\sports3\pc\index.blade.php)
截圖:
mysql 5.7
php 7.3
windwos
錯誤提示 關鍵詞為: this is incompatible with sql_mode=only_full_group_by
incompatible: 不一致
mysql遇見Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的問題
問題出現的原因:
MySQL 5.7.5及以上功能依賴檢測功能。如果啟用了ONLY_FULL_GROUP_BY SQL模式(預設情況下),MySQL將拒絕選擇列表,HAVING條件或ORDER BY列表的查詢引用在GROUP BY子句中既未命名的非集合列,也不在功能上依賴於它們。(5.7.5之前,MySQL沒有檢測到功能依賴關係,預設情況下不啟用ONLY_FULL_GROUP_BY。有關5.7.5之前的行為的說明,請參見“MySQL 5.6參考手冊”。)
解決方法一:
開啟navcat,
用sql查詢:
select @@global.sql_mode
查詢出來的值為:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
去掉ONLY_FULL_GROUP_BY,重新設定值。
set @@global.sql_mode
='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
如下圖:
解決方法二:
成功的步驟:
iterm開啟
sudo vim /etc/mysql/conf.d/mysql.cnf
滾動到檔案底部複製並貼上
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
到檔案的底部
儲存並退出輸入模式
sudo service mysql restart
重啟MySQL。
完成!
是因為
這是因為laravel mysql資料庫開啟了嚴格模式,導致很多mysql語句可能會報錯,我們可以將其關閉即可
找到config/database.php,修改’strict’ => true,改為false即可
本作品採用《CC 協議》,轉載必須註明作者和本文連結