Reputation: 37
when i want to generate Entity from data base i have this Error:
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it
how can i resolve this issue.
Thanks in advance
Upvotes: 2
Views: 2925
Reputation: 1279
If you really want to work with enums and don't convert them to strings, you should implement your custom type (it's really not a big deal). See enter link description here
But also, you have to extend list of types on your platform. So, simplest way to do that - override useless method \Doctrine\DBAL\Types\Type::getMappedDatabaseTypes with your own so like that:
class EnumType extends Type
{
const NAME = "enum";
// ... (your implemented methods)
public function getMappedDatabaseTypes(AbstractPlatform $platform)
{
return ['enum'];
}
}
Have a fun :)
Upvotes: 0
Reputation: 2547
Add the following line to your bootstrap.php
$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
Upvotes: 2
Reputation: 9008
You could try to do something like this in the onBootstrap
module of your Module.php
, to tell Doctrine to treat your enum
like a string
$em = $e->getApplication()->getServiceManager()->get('Doctrine\ORM\EntityManager');
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
Upvotes: 2