From 58162b9b2af351151917f6c98135e7f4982310b8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 12 Jul 2018 17:31:54 +0200 Subject: [PATCH 1/2] Mentioned the 767 bytes index limit and its solution --- doctrine.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doctrine.rst b/doctrine.rst index 00de1cf1b58..f69d080d9a6 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -149,6 +149,15 @@ can automatically generate an empty ``test_project`` database for you: support 4-byte unicode characters, and strings containing them will be truncated. This is fixed by the `newer utf8mb4 character set`_. + .. caution:: + + MySQL sets a `limit of 767 bytes for the index key prefix`_. When using + ``utf8mb4``, string columns with 255 character length surpass that limit. + This means that any column of type ``string`` and ``unique=true`` must + set its ``length`` to ``190``. Otherwise, you'll see this error: + *"[PDOException] SQLSTATE[42000]: Syntax error or access violation: + 1071 Specified key was too long; max key length is 767 bytes"*. + .. note:: If you want to use SQLite as your database, you need to set the path @@ -838,3 +847,4 @@ Learn more .. _`FrameworkExtraBundle documentation`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html .. _`newer utf8mb4 character set`: https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html .. _`Transactions and Concurrency`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html +.. _`limit of 767 bytes for the index key prefix`: https://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html From b7f3be4ab19ba2d4e1721b13515da0e030ba89bf Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 16 Jul 2018 10:15:16 +0200 Subject: [PATCH 2/2] Minor tweak --- doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctrine.rst b/doctrine.rst index f69d080d9a6..baafcace6c4 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -154,7 +154,7 @@ can automatically generate an empty ``test_project`` database for you: MySQL sets a `limit of 767 bytes for the index key prefix`_. When using ``utf8mb4``, string columns with 255 character length surpass that limit. This means that any column of type ``string`` and ``unique=true`` must - set its ``length`` to ``190``. Otherwise, you'll see this error: + set its maximum ``length`` to ``190``. Otherwise, you'll see this error: *"[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes"*.