Files
kulakpos_web/walkthroughs/2026-04-18_00f20fb7_Walkthrough__PostgreSQL_Compatibility_Fixes.md
eko54r 05fd3230b8
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped
update marketing
2026-05-14 11:55:22 +07:00

2.2 KiB

Walkthrough - PostgreSQL Compatibility Fixes

I have resolved the 500 Internal Server Error encountered when fetching dashboard data. The issue was caused by MySQL-specific SQL syntax in the backend controllers, which is incompatible with your PostgreSQL database.

Changes Made

Backend API

1. Statistics Controller Fix

Updated StatisticsController.php to use PostgreSQL's TO_CHAR function and double-quoted camelCase column names like "totalAmount".

Before:

$sales_data = Sale::selectRaw("DATE_FORMAT(created_at, '%Y-%m-%d') as date, SUM(totalAmount) as amount")

After:

$sales_data = Sale::selectRaw("TO_CHAR(created_at, 'YYYY-MM-DD') as date, SUM(\"totalAmount\") as amount")

2. Report Controller Fix

Updated AcnooReportController.php to use the PostgreSQL cast operator ::date and quoted camelCase columns ("saleDate", "lossProfit", etc.).

Example After:

DB::raw('"saleDate"::date as date')
DB::raw('SUM("lossProfit") as total_sale_income')

3. Other Database Compatibility Fixes

  • Admin Dashboard: Replaced MONTHNAME() with TO_CHAR(..., 'Month') in DashboardController.php.
  • Transfer Model: Replaced CAST(... AS UNSIGNED) with CAST(... AS INTEGER) in Transfer.php.

Verification Results

Manual Verification Required

As the backend environment is restricted, please perform the following steps to verify the fix:

  1. Ensure your PostgreSQL database is running.
  2. Restart your Laravel development server: php artisan serve.
  3. Run your Flutter application and navigate to the dashboard.
  4. Verify that the "Failed to fetch business data 500" error no longer appears and that data is displayed correctly.