【问题标题】:Enum enabling issues in Symfony2/Doctrine2Symfony2/Doctrine2 中的枚举启用问题
【发布时间】:2015-10-20 23:34:37
【问题描述】:

作为我的问题的序言,我已经尝试了this StackExchange question 建议的所有解决方案。

这是给出的错误:

[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.

此错误与我在尝试任何修复之前收到的错误相同。

这是 config.yml 文件中当前的 Doctrine 代码:

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

vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php下的相关代码:

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

我会尝试接受此处显示的建议:Doctrine Cookbook,但该文章没有明确指定将此代码注入哪个文件(具体参考选项 1)。在我看来,显示的代码将被第二个代码示例底部注入的代码覆盖。

这发生在数据库中的所有枚举上。手动更改数据库并不完全是一种选择。我还能尝试什么?

【问题讨论】:

  • ENUM 通常是一种邪恶的数据类型!还有更多示例,但您可以从 this 开始
  • @BentCoder 如果我可以改变它,我会改变它,但它不是我要改变的数据库。

标签: php mysql symfony doctrine-orm enums


【解决方案1】:

不确定目的:enumAddressSource: string

不应该 enum: string (如前面的行)就足够了吗?

您收到的错误消息基本上是告诉您没有称为“enumAdressSource”的类型,因此没有此类类型可以映射到字符串。您在这里映射类型,而不是字段。

【讨论】:

    【解决方案2】:

    错误的原因是嵌套在 MySQL 数据库列中的 cmets。我从来没有想到 Doctrine 会阅读这些 cmets 并尝试解释它们。删除 cmets 解决了这个问题。我找不到有关此问题的更多文档。如果有人有好的来源,请评论(或编辑)这个答案。

    【讨论】:

      猜你喜欢
      • 2017-03-03
      • 2013-08-26
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多