请求未知数据库类型枚举,学说

Unknown database type enum requested,Doctrine

当我想从数据库生成实体时,我遇到了这个错误:

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

我该如何解决这个问题。

提前致谢

你可以尝试在你的 Module.phponBootstrap 模块中做这样的事情来告诉 Doctrine 把你的 enum 当作一个字符串

$em = $e->getApplication()->getServiceManager()->get('Doctrine\ORM\EntityManager');
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');

将以下行添加到您的 bootstrap.php

$entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');

如果您真的想使用枚举并且不想将它们转换为字符串,您应该实现您的自定义类型(这真的没什么大不了的)。 参见 enter link description here

而且,您必须扩展您平台上的类型列表。 所以,最简单的方法是用你自己的方法覆盖无用的方法 \Doctrine\DBAL\Types\Type::getMappedDatabaseTypes ,就像这样:

class EnumType extends Type
{
    const NAME = "enum";

    // ... (your implemented methods)

    public function getMappedDatabaseTypes(AbstractPlatform $platform)
    {
        return ['enum'];
    }
}

玩得开心:)