如何在Symfony 2 / Doctrine中启用ENUM [英] How to enable ENUMs in Symfony 2 / Doctrine

查看:129
本文介绍了如何在Symfony 2 / Doctrine中启用ENUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当运行 doctrine:mapping:import 我收到错误:


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

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

似乎我需要设置 use_native_enum to true some how。然而,所有的文档和博客文章都参考了Symfony< 1.4。 Symfony 2中有什么解决方案吗?

It seems I need to set use_native_enum to true some how. However, all documentation and blog posts are refering to Symfony < 1.4. Is there any what would be the solution in Symfony 2?

推荐答案

对于Symfony 2项目,将其添加到 app / config.yml

For Symfony 2 projects, add this to the doctrine dbal configuration in app/config.yml:

doctrine:
    dbal:
        mapping_types: 
            enum:       string 

我的完整的教条配置如下所示:

My full doctrine config looks like this:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        mapping_types:
            enum: string
            set: string
            varbinary: string
            tinyblob: text

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

代码广告来自此处

然后运行:

app / console doctrine:schema:update --force --dump-sql - -ansi

这篇关于如何在Symfony 2 / Doctrine中启用ENUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆