@@ -131,10 +131,6 @@ for you:
131
131
$ php bin/console doctrine:database:drop --force
132
132
$ php bin/console doctrine:database:create
133
133
134
- There's no way to configure these defaults inside Doctrine, as it tries to be
135
- as agnostic as possible in terms of environment configuration. One way to solve
136
- this problem is to configure server-level defaults.
137
-
138
134
Setting UTF8 defaults for MySQL is as simple as adding a few lines to
139
135
your configuration file (typically ``my.cnf ``):
140
136
@@ -145,6 +141,54 @@ for you:
145
141
collation-server = utf8mb4_general_ci # Replaces utf8_general_ci
146
142
character-set-server = utf8mb4 # Replaces utf8
147
143
144
+ You can also change the defaults for Doctrine so that the generated SQL
145
+ uses the correct character set.
146
+
147
+ .. configuration-block ::
148
+
149
+ .. code-block :: yaml
150
+
151
+ doctrine :
152
+ charset : utf8mb4
153
+ dbal :
154
+ default_table_options :
155
+ charset : utf8mb4
156
+ collate : utf8mb4_unicode_ci
157
+
158
+ .. code-block :: xml
159
+
160
+ <!-- app/config/config.xml -->
161
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
162
+ <container xmlns =" http://symfony.com/schema/dic/services"
163
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
164
+ xmlns : doctrine =" http://symfony.com/schema/dic/doctrine"
165
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
166
+ http://symfony.com/schema/dic/services/services-1.0.xsd
167
+ http://symfony.com/schema/dic/doctrine
168
+ http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" >
169
+
170
+ <doctrine : config >
171
+ <doctrine : dbal
172
+ charset =" utf8mb4" >
173
+ <doctrine : default-table-option name =" charset" >utf8mb4</doctrine : default-table-option >
174
+ <doctrine : default-table-option name =" collate" >utf8mb4_unicode_ci</doctrine : default-table-option >
175
+ </doctrine : dbal >
176
+ </doctrine : config >
177
+ </container >
178
+
179
+ .. code-block :: php
180
+
181
+ // app/config/config.php
182
+ $configuration->loadFromExtension('doctrine', array(
183
+ 'dbal' => array(
184
+ 'charset' => 'utf8mb',
185
+ 'default_table_options' => array(
186
+ 'charset' => 'utf8mb4'
187
+ 'collate' => 'utf8mb4_unicode_ci'
188
+ )
189
+ ),
190
+ ));
191
+
148
192
We recommend against MySQL's ``utf8 `` character set, since it does not
149
193
support 4-byte unicode characters, and strings containing them will be
150
194
truncated. This is fixed by the `newer utf8mb4 character set `_.
0 commit comments