主义2:类型x已经存在 [英] Doctrine2: Type x already exists
问题描述
我的Doctrine API有问题.
I have a problem with the Doctrine API.
我想添加一个新的教义类型.我按照本文档创建了该类,并在自定义驱动程序中添加了该类型.
I want to add a new Doctrine Type. I followed this documentation to create the class, and I have added the type in my custom driver.
Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
$this->registerDoctrineTypeMapping("CustomType", "custom");
我的问题在执行php app/控制台缓存时清除:清除.
My problem append when I execute php app/console cache:clear.
[Doctrine\DBAL\DBALException]
Type custom already exists.
经过几次搜索,我发现在Doctrine \ DBAL \ Types \ Type :: addType(...)中,如果知道类型,则会引发异常……我不明白为什么会引发此错误.
After few searches, I have found in Doctrine\DBAL\Types\Type::addType(…) throw an exception if the type is knew… I don't understand why this error is throwing.
推荐答案
我发现了我的问题!
我不知道为什么,但是我的自定义类型一次又一次地加载.
I don't know why, but my custom type is loading again and again.
要解决此问题,请添加类似检查的代码.
To resolve this problem, adding this code like checking.
if (!Type::hasType("custom")) {
Type::addType("custom", "Namespace\NameBundle\Types\CustomType");
$this->registerDoctrineTypeMapping("CustomType", "custom");
}
它有效!
这篇关于主义2:类型x已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!