Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it. Symfony 4

I created a fresh symfony4 project. Made user Entity using php bin/console make:user, then tried to migrate using php bin/console make:migration. But then the error pops up

In AbstractPlatform.php line 434:

Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

The strange thing is the User entity doesn't have any enum type rather it has a json column of roles, I suppose this is the reason.

 /**
 * @ORM\Column(type="json")
 */
 private $roles = [];

I have seen some answers for the similar question for laravel, But don't know how to fix it in symfony4.

like image 695
Shobi Avatar asked Feb 06 '19 06:02

Shobi


2 Answers

Couldn't reproduce your issue. But anyway you can set up enum type in doctrine.yaml like

doctrine:
    dbal:
       .....
        mapping_types:
            enum: string
like image 110
LeshaZ Avatar answered Nov 15 '22 06:11

LeshaZ


To fix this, you can register that type mapping on your migration:

DB::connection()->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');

Also, you could register it on app\Providers\AppServiceProvider.php.

    public function boot() {
        // ...

        DB::connection()
            ->getDoctrineSchemaManager()
            ->getDatabasePlatform()
            ->registerDoctrineTypeMapping('enum', 'string');

        // ....
    }

Source: https://github.com/doctrine/dbal/issues/3161#issuecomment-542814085

like image 3
anayarojo Avatar answered Nov 15 '22 07:11

anayarojo