-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Doctrine generates too long index keys for username_canonical & email_canonical columns #1919
Comments
I can think of one way to fix this, but its a BC break. Instead of storing the actual value you store the sha1 hash (40 bytes) of the original value instead. |
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:
|
I can't figure out a way to override the FOSUserBundle/.../User.orm.xml I've added a app/Resources/FOSUserBundle/config/doctrine-mapping/User.orm.xml with a field length of 191, but it still add 255 length field... What is the proper way to change it? Thanks! |
You create custom mapping for the whole bundle. And don't auto register the default one. |
Thanks for your reply. Can you provide an example of the custom mapping for the whole bundle? I see how to make it for the entity but not the bundle. :( |
Hi, Thanks. |
This annotation seems to work on the User object /**
* @ORM\Entity
* @ORM\Table(name="fos_user")
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="usernameCanonical",
* column=@ORM\Column(
* name = "username_canonical",
* length = 191,
* unique = true
* )
* ),
* @ORM\AttributeOverride(name="emailCanonical",
* column=@ORM\Column(
* name = "email_canonical",
* length = 191,
* unique = true
* )
* )
* })
*/
class User extends BaseUser
{
//...
} |
Thanks @ParisLiakos this solved my problem. |
I had this on a shared host allowing only MyISAM, after not having any problem in my development env using innodb. |
@EzekielYovel I don't think MyISAM vs innodb makes any difference here. |
I may be wrong, but as soon as I added 'options={"engine": "MyISAM"}' to my User class I had the same error message in my development env, so I think myisam vs innodb does make a difference. |
For clarity, here is what I did. First I've added the 'options={"engine": "MyISAM"}' to my user class,
here's the output:
|
I stand corrected, the max length varies between engines. Thanks, for your explanation though. http://stackoverflow.com/a/3489331 |
The annotations suggested by @ParisLiakos solve the problem, but be aware it may cause you to run into what seems to be a Doctrine bug, when using
Seems like it's related to this bug, and various people are having a similar issue with it. |
Just follow @umstek suggestion, and it's seems solve the problem. Since utf8 required 3 byte to encode each char, have varchar(255) as unique index (3 * 255) not reach the innodb limit (767).
But, if user typing accent is your concern, then utf8mb4 is more reliable choice. So, just decrease the username_connocial and email_connocial length or use subset index length. Good read: https://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql |
I'm not sure if there is a related issue, but I've added override:
but it seems too short (191 vs 255). Haven't actually registered a user so I can't confirm. |
update your MariaDB at least > 10.2 to update length=255 |
I just changed the length=255, to length=191 and it was ok for me |
As of 1.3, it roughly generates the following CREATE TABLE query for mysql:
Which causes the following issue:
We workaround this by manually updating the UNIQUE INDEX and add their lengths:
The text was updated successfully, but these errors were encountered: