mardi 3 mars 2020

SQLSTATE[42000]: Syntax error or access violation: 1055 Laravel 5.8 MySQL

I have MySQL Query (this is work) like :

SELECT 
    project_bills.*, 
    project_deliveryorder.totalcost,
    project_deliveryorder.deliveryorder_number,
    project_deliveryorder.deliveryorder_subject,
    SUM(project_bills_payment.payment_amount) AS TOTAL
FROM 
    project_bills 
JOIN
    project_deliveryorder ON project_bills.id_deliveryorder = project_deliveryorder.id
JOIN
    project_bills_payment ON project_bills.id = project_bills_payment.id_bill
GROUP BY
    project_bills.id
ORDER BY
    project_bills.bill_date, project_bills.id DESC;

and I tried to translate to Laravel format like :

DB::table('project_bills')
    ->join('project_deliveryorder', 'project_bills.id_deliveryorder', '=', 'project_deliveryorder.id')
    ->join('project_bills_payment', 'project_bills.id', '=', 'project_bills_payment.id_bill')
    ->select('project_bills.*', 'project_deliveryorder.totalcost', 'project_deliveryorder.deliveryorder_number', 'project_deliveryorder.deliveryorder_subject', DB::raw('SUM(project_bills_payment.payment_amount) AS TOTAL'))
    ->groupBy('project_bills.id')
    ->orderBy('project_bills.bill_date', 'DESC')
    ->orderBy('project_bills.id', 'DESC')
    ->get();

and then I got some error like :

SQLSTATE[42000]: Syntax error or access violation: 1055 'db_tcm.project_bills.id_deliveryorder' isn't in GROUP BY

I have read Group by not working - Laravel in Stack Overflow too, so what best way to fix this issue?

  • Change database config ('strict' => true)?
  • Disable “ONLY_FULL_GROUP_BY” pada MySQL?
  • Or re-build the Laravel query builder?


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire