@@ -131,10 +131,6 @@ for you:
131131 $ php bin/console doctrine:database:drop --force
132132 $ php bin/console doctrine:database:create
133133
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-
138134 Setting UTF8 defaults for MySQL is as simple as adding a few lines to
139135 your configuration file (typically ``my.cnf ``):
140136
@@ -144,6 +140,60 @@ for you:
144140# Version 5.5.3 introduced "utf8mb4", which is recommended
145141collation-server = utf8mb4_general_ci# Replaces utf8_general_ci
146142character-set-server = utf8mb4# Replaces utf8
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+ ..code-block ::yaml
149+
150+ doctrine :
151+ dbal :
152+ default_table_options :
153+ charset :utf8mb4
154+ collate :utf8mb4_unicode_ci
155+
156+ ..code-block ::xml
157+
158+ <!-- app/config/config.xml-->
159+ <?xml version =" 1.0" encoding =" UTF-8" ?>
160+ <container xmlns =" http://symfony.com/schema/dic/services"
161+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
162+ xmlns : doctrine =" http://symfony.com/schema/dic/doctrine"
163+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
164+ http://symfony.com/schema/dic/services/services-1.0.xsd
165+ http://symfony.com/schema/dic/doctrine
166+ http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd" >
167+
168+ <doctrine : config >
169+ <doctrine : dbal
170+ driver =" %database_driver%"
171+ host =" %database_host%"
172+ dbname =" %database_name%"
173+ user =" %database_user%"
174+ password =" %database_password%" >
175+ <doctrine : default-table-option name =" charset" >utf8</doctrine : default-table-option >
176+ <doctrine : default-table-option name =" collate" >utf8_unicode_ci</doctrine : default-table-option >
177+ </doctrine : dbal >
178+ </doctrine : config >
179+ </container >
180+
181+ ..code-block ::php
182+
183+ // app/config/config.php
184+ $configuration->loadFromExtension('doctrine', array(
185+ 'dbal' => array(
186+ 'driver' => '%database_driver%',
187+ 'host' => '%database_host%',
188+ 'dbname' => '%database_name%',
189+ 'user' => '%database_user%',
190+ 'password' => '%database_password%',
191+ 'default_table_options' => array(
192+ 'charset' => 'utf8mb4'
193+ 'collate' => 'utf8mb4_unicode_ci'
194+ )
195+ ),
196+ ));
147197
148198 We recommend against MySQL's ``utf8 `` character set, since it does not
149199 support 4-byte unicode characters, and strings containing them will be