我创建了一个数据库视图,当我对这个视图使用 laravel 分页时,它会抛出:
SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: select count(*) as aggregate from `parameter_log_site_detail` where `site_id` = EPE)
但是此错误仅在实时服务器中弹出。分页在本地服务器上工作正常。
数据库视图: (parameter_log_site_detail)
select `t`.`site_id` AS `site_id`,cast(`t`.`logged_at` as date) AS `logged_on`,`t`.`daily_generation` AS `daily_generation`,`t`.`reading` AS `tot_reading` from `parameter_log_tab` `t` order by cast(`t`.`logged_at` as date) desc
模型:
public function scopeSiteDailyReadings($query)
{
return $query->from('parameter_log_site_detail');
}
控制器:
$generations = EnergyGeneration::siteDailyReadings()->where('site_id', $site_id)->orderBy('logged_on', 'desc')->paginate(15);
实时服务器信息
MySQL Server version: 5.6.37 - MySQL Community Server (GPL)
PHP version: 5.6.30
Laravel version: 5.4
本地服务器信息(正常运行的地方)
MySQL Server version: 5.7.19 - MySQL Community Server (GPL)
PHP version: 7.1.7
Laravel version: 5.4
有人可以解释这可能是什么原因吗?我读到了 ONLY_FULL_GROUP_BY。但无法弄清楚这是因为服务器版本是5.6.*的原因。