Pat*_*ick 4 php mysql doctrine symfony doctrine-orm
我正在使用Doctrine的枚举类型来跟踪我在Symfony应用程序中使用的实体的状态。我正在使用(大致)这里描述的方法:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/mysql-enums.html
我尝试更新数据库架构时遇到了问题。我收到以下错误:
[Doctrine\DBAL\DBALException]
Unknown column type "EnumStatusType" requested. Any Doctrine type that you use has to be registered
with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrin
e\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might
have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctr
ineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type nam
e is empty you might have a problem with the cache or forgot some mapping information.
Run Code Online (Sandbox Code Playgroud)
该错误在某种程度上非常有帮助-就像文档一样-但是这两个资源都遗漏了两条信息:我应该在哪个文件中使用addType()注册我的新类型?
第二个次级问题:如示例所示,我是否应该静态调用addType()方法?如果不是,我应该如何检索对象以非静态方式调用该方法?
您可以使用symfony配置添加自定义类型。
如果您正在使用symfony 4,则可以输入 config/packages/doctrine.yaml以下代码:
doctrine:
dbal:
types:
your_custom_type: App\Type\YourCustomType
Run Code Online (Sandbox Code Playgroud)
如果您使用的是symfony 3.x,则可以app/config/config.yml将此代码添加到此文件中:
doctrine:
dbal:
types:
your_custom_type: AppBundle\Type\YourCustomType
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1890 次 |
| 最近记录: |