简体   繁体   English

Symfony2 / Doctrine2中的枚举启用问题

[英]Enum enabling issues in Symfony2/Doctrine2

To preface my question, I have tried every solution suggested by this StackExchange question . 作为我问题的开头 ,我尝试了此StackExchange问​​题建议的所有解决方案。

This is the error given: 这是给出的错误:

[Doctrine\DBAL\DBALException]
Unknown column type "enumAddressSource" requested. Any Doctrine type t
hat you use has to be registered with \Doctrine\DBAL\Types\Type::addTy
pe(). You can get a list of all the known types with \Doctrine\DBAL\Ty
pes\Type::getTypesMap(). If this error occurs during database introspe
ction then you might have forgot to register all database types for a
Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or h
ave your custom types implement Type#getMappedDatabaseTypes(). If the
type name is empty you might have a problem with the cache or forgot s
ome mapping information.

This error is identical with the one that I had received prior to trying any fixes. 此错误与尝试任何修复之前收到的错误相同。

This is the current Doctrine code in the config.yml file: 这是config.yml文件中的当前教义代码:

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        mapping_types:
            enum: string
            enumAddressSource: string
            # if using pdo_sqlite as your database driver:
            #   1. add the path in parameters.yml
            #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
            #   2. Uncomment database_path in parameters.yml.dist
            #   3. Uncomment next line:
            #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

The relevant code under vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php: 在vendor / doctrine / dbal / lib / Doctrine / DBAL / Platforms / MySqlPlatform.php下的相关代码:

protected function initializeDoctrineTypeMappings()
{
    $this->doctrineTypeMapping = array(
        'tinyint'       => 'boolean',
        'smallint'      => 'smallint',
        ...
        'enum'          => 'string',
        'enumAddressSource' => 'string',
    );

I would try to take the advice shown here: Doctrine Cookbook , but the article does not plainly specify which file this code is to be injected into (Referring specifically to option 1). 我将尝试采用此处显示的建议: Doctrine Cookbook ,但是本文并没有明确指定将此代码注入到哪个文件中(专门参考选项1)。 It also appears to me that the code shown would be covered by the code injected at the bottom of the second code example. 在我看来,所显示的代码将被第二个代码示例底部注入的代码覆盖。

This occurs for all enums in the database. 数据库中的所有枚举都会发生这种情况。 Changing the database manually isn't exactly an option. 并不是完全可以手动更改数据库。 What else can I try? 我还能尝试什么?

not sure of the purpose of: enumAddressSource: string 不确定用途:enumAddressSource:字符串

Shouldn't enum: string (as in the line before it) be enough? 应该不应该枚举:字符串(如前一行所示)就足够了?

There error message you are getting is basically telling you that there is no type thats called "enumAdressSource", thus no such type can be mapped to string. 您收到的错误消息基本上是在告诉您没有所谓的“ enumAdressSource”类型,因此无法将此类类型映射到字符串。 You are mapping types, not fields here. 您正在映射类型,而不是此处的字段。

The causes of the error were comments nested in the columns of the MySQL database. 错误的原因是嵌套在MySQL数据库列中的注释。 I never would have guessed that Doctrine would read these comments and try to interpret them. 我从没想过教义会读这些评论并试图解释它们。 Deleting the comments fixed the problem. 删除评论可解决此问题。 I could not find further documentation on this issue. 我找不到有关此问题的更多文档。 If anyone has a good source, please comment (or edit) this answer. 如果任何人都有很好的消息来源,请评论(或编辑)此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM