Skip to content

Steps to configure doctrine/orm for utf8mb4 aren't correct #5526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samjarrett opened this issue Jul 16, 2015 · 4 comments
Closed

Steps to configure doctrine/orm for utf8mb4 aren't correct #5526

samjarrett opened this issue Jul 16, 2015 · 4 comments

Comments

@samjarrett
Copy link
Contributor

PR #5100 took on the task of changing information on setting mysql server defaults from UTF8 to utf8mb4. However doctrine does not actually obey this - at some point doctrine started explicitly setting column and table-level collation/charsets, and the value seems to be fixed (by default) to standard utf8.

Alternatives to force utf8mb4 for your entities require the following annotation:

@ORM\Table(options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"})

and while this seems hacky, it does the job.

There is a PR open for DoctrineBundle that should allow users to set a global option in their projects, although until this is merged, the documentation should be revised to remove this section as it may be dangerous for users relying upon it as the solution.

@DHager
Copy link
Contributor

DHager commented Jul 16, 2015

To quibble a little bit: I believe #5100 is still correct... it's just that the scope of what's being configured is limited to the MySQL server itself. That'll affect SQL code that doesn't explicitly call for a given character set or collation, but won't override Doctrine when it explicitly tells the server to do something else.

However doctrine does not actually obey this

I agree that it's a pain, but changing its behavior at this point could be a backwards-compatibility break, for all the people who thought omitting the table-options was guaranteed to give them utf8.

There's some more discussion on that in doctrine/dbal#851.

@Tobion
Copy link
Contributor

Tobion commented Nov 13, 2017

This is fixed as the documentation includes now the following snippet which both set the default charset for tables and correctly set the connection charset.

doctrine:
    dbal:
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

@xabbuh
Copy link
Member

xabbuh commented Nov 14, 2017

closing as fixed by #6274

@xabbuh xabbuh closed this as completed Nov 14, 2017
@rquadling
Copy link

With regard to the collation, https://dev.mysql.com/doc/refman/8.0/en/charset-collation-names.html contains some very useful info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants