2016-09-14 113 views
0

使用学说,我被介绍了以下错误:未知列类型“将varchar”

[2016-09-14 21:24:44] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\DBALException: "Unknown column type "varchar" 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 \Doctrine\DBAL\Types\Type::getTypeMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information." at /var/www/project/apps/ProjectName/trunk/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 114 {"exception":"[object] (Doctrine\\DBAL\\DBALException(code: 0): Unknown column type \"varchar\" 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 \\Doctrine\\DBAL\\Types\\Type::getTypeMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information. at /var/www/project/apps/ProjectName/trunk/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:114)"} [] 

相关类看起来如此

<?php 

namespace Project\DBALBundle\Entity\Url; 

use Doctrine\ORM\Mapping as ORM; 
use JMS\Serializer\Annotation as JMSS; 

/** 
* Profile 
* 
* @ORM\Table(name="Profile") 
* @ORM\Entity(repositoryClass="Project\DBALBundle\Entity\Url\ProfileRepository") 
*/ 
class ProfileRepository { 
    /** 
    * @var string $id 
    * 
    * @ORM\Column(name="id", type="integer", length=11, nullable=false) 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 
    /** 
    * @var string $label 
    * 
    * @ORM\Column(name="label", type="string", length=50, nullable=false) 
    */ 
    private $label; 

    /** 
    * @return string 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * @param string $id 
    */ 
    public function setId($id) 
    { 
     $this->id = $id; 
    } 

    /** 
    * @return string 
    */ 
    public function getLabel() 
    { 
     return $this->label; 
    } 

    /** 
    * @param string $label 
    */ 
    public function setLabel($label) 
    { 
     $this->label = $label; 
    } 

    public function __toString() 
    { 
     return $this->label; 
    } 
} 

有了上面的类和注释定义的映射,我收到错误。但是,如果我将字段private $label更改为private $labelField并更新关联的引用,则一切正常,数据按预期访问。

就我已经能够搜索,private $label没有什么特别之处。它不是一个保留的关键字,我没有发现任何关于它的任何特别的内容,无论是使用PHP本身还是特定的Doctrine。那么为什么这会打破?

回答

1

我的猜测是它是一个缓存问题。你有可能试图在某些时候这个代码,

/** 
* @var string $label 
* 
* @ORM\Column(name="label", type="varchar", length=50, nullable=false) 
*/ 
private $label; 

这个类已经得到了由opcache(或类似)的缓存。 Opcache不注意注释(它只是一个注释),所以无论你在注释中改变了什么,它仍然使用这个缓存版本的代码。

但是,当您更改属性名称时,它意识到它是较新版本的类并再次解析注释(这就是为什么labelField代码有效)。

但这只是一个猜测。我会尝试使用Xdebug进行调试以找出确切的问题。

P.S.学说2.3版本相当陈旧,不是吗?

+0

是的,没有意识到Symfony正在缓存它,或者至少在无数次其他更改后假定它的整个文件将在缓存中进行更新。此外,是的,它是一个传统的内部工具,有望在不久的将来被替换,所以我们坚持2.3。 –