【发布时间】: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