Warm tip: This article is reproduced from stackoverflow.com, please click
doctrine-orm mysql symfony utf-8 orm

Symfony 4 SQLSTATE[42000] Specified key was too long

发布于 2020-03-31 22:54:30

I am trying to create database from Entity in Symfony 4. However the result is:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

I know this is because it is trying to use utf8mb4 charset and utf8mb4_unicode_ci collation. I've tried to replace my doctrine.yaml file to utf8 and utf8_unicode_ci as well as:

@ORM\Table(name="users", options={"collate"="utf8_unicode_ci", "charset"="utf8", "engine"="MyISAM"})

But it's still trying to use utf88mb4. How can I force it to use utf8?

Questioner
Janusz Kubala
Viewed
204
Janusz Kubala 2018-06-09 18:37

OK I have found an answer, so basically I had a lot of migration files and php was constantly trying to create database with old configuration. To properly create it I deleted Migrations directory and used

php bin/console doctrine:cache:clear-metadata.

That helped, now creator used new configuration.