Doctrine2: Type x already exists

倾然丶 夕夏残阳落幕 提交于 2020-01-03 20:33:09

问题


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");

My problem append when I execute php app/console cache:clear.

[Doctrine\DBAL\DBALException]
Type custom already exists.

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.


回答1:


I have found my problem !

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");
}

It works !



来源:https://stackoverflow.com/questions/20884601/doctrine2-type-x-already-exists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!