FOSUserBundle: Doctrine generates too long index keys for username_canonical & email_canonical columns
As of 1.3, it roughly generates the following CREATE TABLE query for mysql:
CREATE TABLE fos_user (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
....
....
username VARCHAR (255) NOT NULL,
username_canonical VARCHAR (255) NOT NULL,
email VARCHAR (255) NOT NULL,
email_canonical VARCHAR (255) NOT NULL,
....
....
UNIQUE INDEX UNIQ_957A647992FC23A8 (username_canonical),
UNIQUE INDEX UNIQ_957A6479A0D96FBF (email_canonical),
....
....
)
Which causes the following issue:
Error Code: 1071
Specified key was too long; max key length is 767 bytes
We workaround this by manually updating the UNIQUE INDEX and add their lengths:
....
UNIQUE INDEX UNIQ_957A647992FC23A8 (username_canonical(20)),
UNIQUE INDEX UNIQ_957A6479A0D96FBF (email_canonical(20)),
....
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18
Commits related to this issue
- Fixes #1919 Account for index length limit on InnoDB + utf8mb4, otherwise the schema update fails. — committed to afilina/FOSUserBundle by afilina 8 years ago
- Merge pull request #2226 from afilina/patch-1 Fixes #1919 — committed to FriendsOfSymfony/FOSUserBundle by XWB 8 years ago
This annotation seems to work on the User object
The cause of this is that Symfony advises you to use utf8mb4_general_ci/utf8mb4 as collation/charset for your database. utf8mb4 takes 4 bytes per char, meaning a 255 char field needs 1020 bytes for an index (that covers the whole length). InnoDB has a max key length of 767 bytes, so that leaves us with a couple of options:
Hi, I’m having the same problem. My software is still in development stage and I need to know whether stepping-down to utf8 will be okay until this issue is fixed.
Thanks.
update your MariaDB at least > 10.2 to update length=255