Categories
Software Development Web Development

How to fix Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL80Platform may not support it.

So you got this lovely error when trying to reverse engineer a database with doctrine. This error means that your database uses ENUM and is probably running on MySQL.

MySQL also contains SET which is about the same as ENUM except enum allows only 1 value from the list( or empty string or NULL) and set allows multiple values from the list. Doctrine doesn’t barf when it sees a SET but it sure does when it sees an ENUM.

baby threw up meme
Doctrine no ENUMs very well

Enums are ok when you know in advance that your will only ever require a small number of options and you will allow empty strings or NULL. I usually go with a table when the number of options will be like 10+ , or I don’t know for sure how many items there could be.

However working with Enums is a little difficult with Doctrine. Especially if you are trying to reverse engineer an existing database, you will get the following error :

doctrine enum barf
Doctrine barfs when it encounters an ENUM

The only way to reverse engineer a database that exists already is to redesign it the Doctrine way. You must remove all Enums and TinyInts. And if those tinyints were used in foreign key ids then, you must hunt down each one and remove it then you can add it again.

Then after you reverse engineer the database you can go into each and every single Entity that should be using an Enum and add the Enum to the Entity like so. Then you can rerun migrations:diff and update the database.

are you kidding me
So do you really want those Enums that bad?

Do you really need enums that bad?

Here is an article about tips and tricks to reverse engineer your existing database.