当我执行命令doctrine:schema:update --dump-sql
时,我得到下面的 SQL 查询来创建一个表。它使用utf8
字符集和utf8_unicode_ci
排序规则。
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;
但是,数据库设置为latin1
和latin1_swedish_ci
。请参阅下面的查询结果,该结果显示了数据库的字符集和排序规则。
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 |
+--------------+-------------+----------------------------+------------------------+----------+
我确实设置了字符集和排序规则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"
我还删除了缓存以防万一。