douan9541 2016-09-14 21:38
浏览 94
已采纳

未知列类型“Varchar”

Using Doctrine, I am being presented the following error:

[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)"} []

the relevant class looks as such

<?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;
    }
}

With the above class and annotation-defined mappings, I receive the error. However, if I change the field private $label to private $labelField and update the associated references, everything works just fine and the data is accessed as expected.

Insofar as I have been able to search, there is nothing special about the field private $label. It is not a reserved keyword, and I can find nothing mentioning anything special about it either with PHP itself or Doctrine specifically. So why does this break?

  • 写回答

1条回答 默认 最新

  • duanmiyang6201 2016-09-14 22:11
    关注

    My guess will be it's a caching problem. You had probably tried at some point this code,

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

    and this class has got cached by opcache (or similar). Opcache pays no attention to annotations (it's just a comments for it), so no matter what you change in annotations, it's still using this cached version of the code.

    But when you change a property name, it realizes that it's a newer version of class and parses annotations once again (that's why with labelField code worked).

    But that's just a speculation. I would try to debug it with Xdebug to find out an exact problem.

    P.S. Doctrine version 2.3 is quite old, isn't it?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化