gpt4 book ai didi

php - Symfony2/Doctrine2 中的枚举启用问题

转载 作者:行者123 更新时间:2023-11-30 22:38:38 24 4
gpt4 key购买 nike

作为我的问题的序言,我已经尝试了 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 ,但是文章并没有明确说明这段代码要注入(inject)到哪个文件中(特指方案一)。在我看来,显示的代码将被第二个代码示例底部注入(inject)的代码覆盖。

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

最佳答案

不确定的目的:enumAddressSource: string

难道 enum: string(如前一行)就足够了吗?

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

关于php - Symfony2/Doctrine2 中的枚举启用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31709739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com