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

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

问题描述

运行 doctrine:mapping:import 时出现错误:

<块引用>

请求的数据库类型未知,DoctrineDBALPlatformsMySqlPlatform 可能不支持.

看来我需要以某种方式将 use_native_enum 设置为 true.但是,所有文档和博客文章都引用了 Symfony <1.4.Symfony 2 中有什么解决方案吗?

解决方案

对于 Symfony 2 项目,将其添加到 app/config.yml 中的 Dotct dbal 配置中:

学说:数据库:映射类型:枚举:字符串

我的完整教义配置如下:

# Doctrine 配置教义:数据库:驱动程序:%database_driver%主机:%database_host%端口:%database_port%数据库名称:%database_name%用户:%database_user%密码:%database_password%字符集:UTF8映射类型:枚举:字符串设置:字符串varbinary: 字符串tinyblob:文本形式:auto_generate_proxy_classes: %kernel.debug%自动映射:真

代码改编自此处

然后运行:

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

When running doctrine:mapping:import i get an error:

Unknown database type enum requested, DoctrineDBALPlatformsMySqlPlatform may not support it.

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?

解决方案

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

Code adapted from here

Then run:

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

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

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