未知的列类型" Varchar"

时间:2016-09-14 21:38:22

标签: php doctrine-orm

使用Doctrine,我遇到以下错误:

[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 个答案:

答案 0 :(得分:1)

我猜这将是一个缓存问题。你可能曾经尝试过这段代码,

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

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

但是当你更改一个属性名称时,它会意识到它是一个较新版本的类并再次解析注释(这就是labelField代码工作的原因)。

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

P.S。 Doctrode 2.3版很老了,不是吗?