请求未知的数据库类型枚举,Doctrine \ DBAL \ Platforms \ MySQL57Platform可能不支持它

时间:2017-11-28 08:17:37

标签: doctrine-orm

我在运行时遇到以下错误,

php bin/console doctrine:schema:validate

[Mapping]  OK - The mapping files are correct.


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


doctrine:schema:validate [--skip-mapping] [--skip-sync] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>.

1 个答案:

答案 0 :(得分:3)

您需要在配置中添加mapping_types

#config/packages/doctrine.yaml doctrine
dbal:
    types:
        myenum: App\DBAL\MyEnumType
    mapping_types:
        enum: string # <- this is what you need!

并在您的实体类中:

class Page {
    ...
    /**
     * @ORM\Column(type="myenum")
     */
    protected $type;
    ...

}

链接到文档如何准备自己的映射类型 doctrine2-mapping-types