Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4, Postgres - `Invalid value for parameter "client_encoding": "utf8mb4"` on running doctrine command

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. enter image description here

Steps to reproduce

  1. On .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".
  2. Create an entity (Any would do) using php bin/console make:entity
  3. Make Migration file 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?

like image 608
Bikal Basnet Avatar asked Sep 14 '18 20:09

Bikal Basnet


2 Answers

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

like image 134
Bikal Basnet Avatar answered Oct 28 '22 02:10

Bikal Basnet


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.

like image 4
Kim Avatar answered Oct 28 '22 04:10

Kim