Skip to content

[Database and Doctrine] utf8mb4 additional note for MySQLΒ #6398

@Fruchuxs

Description

@Fruchuxs

Hello,
I suggest to add a note to the utf8mb4 configuration for indezies and unique entity properties. If a property is marked as unique in the doctrine configuration like in an annotation and doctrine is configured to use utf8mb4, the maximum length of this field needs to be adjusted to a maximum of 190 characters (for MySQL and maybe mandriva db a MySQL Distri - isn't it?).

E.g.:
@ORM\Column(type="string", length=190, nullable=false, unique=true)

I will try to explain why.
I have set up my configuration to use utf8mb4 as default. As I wanted to generate my tables, I run into the following error:
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

So I was wondering whats happen. I have pointed out, that MySQL can only indexing 767 Bytes. MySQLs standard UTF8 uses 3 bytes for char encoding and a varchar has a maximum of 255 characters => 255 * 3 Byte = 765 Byte. But utf8mb4 uses 4 Bytes:767 Bytes / 4 Bytes/Character = 191.75 Characters.

I use MySQL v. 5.6.25.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoctrinehasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions