SQLSTATE[42000]: Syntax error or access violation: 1055 'hammer.vehicle.consignor_id' isn't in GROUP BY (SQL: select `vehicle`.*, `vehicle_brand`.`vehicle_brand_name`, `vehicle_model`.`vehicle_model_name`, `vehicle_variant`.`vehicle_variant_name`, `vehicle_model`.`year`, `vehicle`.`vehicle_id` from `vehicle` left join `vehicle_brand` on `vehicle_brand`.`vehicle_brand_id` = `vehicle`.`vehicle_brand_id` left join `vehicle_model` on `vehicle_model`.`vehicle_brand_id` = `vehicle_brand`.`vehicle_brand_id` left join `vehicle_variant` on `vehicle_variant`.`vehicle_model_id` = `vehicle_model`.`vehicle_model_id` group by `vehicle`.`vehicle_id` limit 10 offset 0)
这是导致错误的laravel代码
\DB::table('vehicle')
->select('vehicle.*', 'vehicle_brand.vehicle_brand_name', 'vehicle_model.vehicle_model_name', 'vehicle_variant.vehicle_variant_name', 'vehicle_model.year', 'vehicle.vehicle_id')
->leftJoin('vehicle_brand', 'vehicle_brand.vehicle_brand_id', '=', 'vehicle.vehicle_brand_id')
->leftJoin('vehicle_model', 'vehicle_model.vehicle_brand_id', '=', 'vehicle_brand.vehicle_brand_id')
->leftJoin('vehicle_variant', 'vehicle_variant.vehicle_model_id', '=', 'vehicle_model.vehicle_model_id')
->where($where)
->groupBy('vehicle.vehicle_id')
->paginate(10);
配置“strict”中的mysql设置已设置为false
答案 0 :(得分:7)
我认为导致问题的是严格模式,检查config/database.php
并检查mysql
内部,然后更改
'strict' => true,
到
'strict' => false,
因为如thread
所述如果设置为true,那么它会在ONLY_FULL_GROUP_BY时添加ONLY_FULL_GROUP_BY 查询。
或者您可以尝试通过执行以下操作来禁用only_full_group_by
设置:
mysql> 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';
mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
根据建议here。