K. Weber
K. Weber

Reputation: 2773

Doctrine ignores the charset and collation of the databaae

When I execute the command doctrine:schema:update --dump-sql, I get the SQL query below to create a table. It uses utf8 charset and utf8_unicode_ci collation.

CREATE TABLE an_example
(id INT AUTO_INCREMENT NOT NULL, 
 id_user INT NOT NULL, 
 date DATETIME NOT NULL, 
 PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

However, the database is set to latin1 and latin1_swedish_ci. See below the results from the query that shows the character set and collation of the database.

mysql> SELECT * FROM information_schema.SCHEMATA  WHERE schema_name = "mydb";
+--------------+-------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+-------------+----------------------------+------------------------+----------+
| def          | mydb        | latin1                     | latin1_swedish_ci      | NULL     |
+--------------+-------------+----------------------------+------------------------+----------+

I did set the character set and collation in config.yml:

doctrine:
    dbal:
        driver: pdo_mysql
        host: '%database_host%'
        port: '%database_port%'
        dbname: '%database_name%'
        user: '%database_user%'
        password: '%database_password%'
        charset: latin1
        default_table_options:
            collate: "latin1_swedish_ci"

I also deleted the cache just in case.

Upvotes: 0

Views: 1043

Answers (1)

Rick James
Rick James

Reputation: 142298

The database settings are only defaults for when you create a table without specifying charset/collation.

The table settings are only defaults for when you create a column without specifying charset/collation.

I recommend you worry, not about the database (SCHEMATA), but about the table and its columns.

Upvotes: 2

Related Questions