The Problem
I have a fresh setup of postgres 10.5 and symfony 4 application running on php 7.1. But when I try running migration. I keep getting the following Invalid value for parameter "client_encoding": "utf8mb4" error.

Steps to reproduce
.env file by modify DSN to correct value based on the your settings for eg. mine wasDATABASE_URL="pgsql://postgres:password@db:5432/a_db". php bin/console make:entity
php bin/console make:migration
Expected Result
I should have received Success message.
So my Question is
What did I miss here as I have followed the documentation?
So my actual client config in the postgres is utf8 not utf8mb4. It seems symfony does not automatically detects the version and database for us.
Symfony 4 has left the standard utf8mb4 for MYSQL in the config file config/packages/doctrine.yaml. This configuration file should not be forgotten to change based on these allowed configuration. So the problem was fixed when I changed the value
from
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
to
dbal:
driver: 'pdo_postgresql'
server_version: '10.5'
charset: utf8
default_table_options:
charset: utf8
collate: utf8_unicode_ci
For me it helped to add the encoding to the Database URL, like this:
postgres://api-platform:!ChangeMe!@db/api?charset=UTF-8
Though this problem only occurred in APP_ENV=prod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With