Doctrine 2:错误:Class“.. \ ..”没有名为“...”的字段或关联 [英] Doctrine 2: Error: Class "..\.." has no field or association named "..."

查看:116
本文介绍了Doctrine 2:错误:Class“.. \ ..”没有名为“...”的字段或关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索时,我想出了许多具有类似问题的人的结果,但是它们总是与关联错误有关。我正在尝试在数据库中的表格中添加一个简单的文本字段,对于我来说,我无法确定这个时间有什么不同 - 当我以前没有遇到任何问题的时候。 p>

我已经将4个不同的实体添加了一个'record_checksum'字段,但是我将只使用一个,这里为了简化这个例子。 (同样的错误发生在所有4)。



这是一个我的Entity\Cloud.php文件的例子,' record_checksum '字段添加在底部:

 使用Doctrine\ORM\Mapping作为ORM; 

命名空间实体;

/ **
* Entity \Cloud
*
* @orm:Table(name =cloud)
* @orm:Entity
* @orm:HasLifecycleCallbacks
* /
class Cloud
{
/ **
* @var整数$ id
*
* @orm:Column(name =id,type =integer,length =13)
* @orm:Id
* @orm:GeneratedValue(strategy =IDENTITY )
* /
private $ id;

/ **
* @var float $ position_x
*
* @orm:列(name =position_x,type =float,length = 9)
* /
private $ position_x;

/ **
* @var float $ position_y
*
* @orm:列(name =position_y,type =float,length = 9)
* /
private $ position_y;

/ **
* @var string $ commit_group
*
* @orm:列(name =commit_group,type =string,length = 32,nullable = true)
* /
private $ commit_group;

/ **
* @var string $ commit_key
*
* @orm:列(name =commit_key,type =string,length = 13,nullable = true)
* /
private $ commit_key;

/ **
* @var string $ record_checksum
*
* @orm:Column(name =record_checksum,type =string,length = 32,nullable = true)
* /
private $ record_checksum;

该类的其余部分是getter / setter方法,所以我将把它留下。要查看整个实体文件,我把它放在了pastebin上( http://pastebin.com/9LheZ6A1 )。几周前我刚刚添加的commit_key,没有任何问题。



现在我更新架构:

  $ doctrine orm:schema -tool:update --dump-sql 
ALTER TABLE cloud ADD record_checksum VARCHAR(32)DEFAULT NULL;
$ doctrine orm:schema-tool:update --force
更新数据库模式...
数据库模式已成功更新!

我已经验证了该字段现在存在于DB表中。



但是,当我运行这样一个简单的DQL查询:

  $ dql =SELECT c.id AS id,c.commit_key AS key,c.record_checksum AS checksum。 
FROM Entity\\Cloud c WHERE c.commit_group =:commit_group;

我收到错误:

  [语义错误]行0,col 42靠近'record_checksum':错误:Class Entity\Cloud没有名为record_checksum的字段或关联,
pre>

我已经把我的头撞在墙上一段时间了。我确定我忽略了一些非常愚蠢的东西。任何帮助是极大的赞赏!
-Nick

解决方案

尝试:


  1. 清除可能包含配置或PHP代码的任何缓存。

  2. 重命名一个字段,以防第一个解决方案无效。


When searching I came up with many results of people having similar problems but they were always related to association errors. I'm trying add a simple text field to a table in a database and, for the life of me, I can't figure out what's different about this time - when I've done it with no problems many times before.

I've added a 'record_checksum' field to 4 different entities, but I will use just one, here to simplify the example. (The same error happens for all 4).

Here is an example of my Entity\Cloud.php file, with the 'record_checksum' field added at the bottom:

use Doctrine\ORM\Mapping as ORM;

namespace Entity;

/**
 * Entity\Cloud
 *
 * @orm:Table(name="cloud")
 * @orm:Entity
 * @orm:HasLifecycleCallbacks
 */
class Cloud
{
    /**
     * @var integer $id
     *
     * @orm:Column(name="id", type="integer", length="13")
     * @orm:Id
     * @orm:GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var float $position_x
     *
     * @orm:Column(name="position_x", type="float", length=9)
     */
    private $position_x;

    /**
     * @var float $position_y
     *
     * @orm:Column(name="position_y", type="float", length=9)
     */
    private $position_y;

    /**
     * @var string $commit_group
     *
     * @orm:Column(name="commit_group", type="string", length=32, nullable=true)
     */
    private $commit_group;

    /**
     * @var string $commit_key
     *
     * @orm:Column(name="commit_key", type="string", length=13, nullable=true)
     */
    private $commit_key;

    /**
     * @var string $record_checksum
     *
     * @orm:Column(name="record_checksum", type="string", length=32, nullable=true)
     */
    private $record_checksum;

The rest of the class is getter/setter methods, so I will leave it out. To see the entire Entity file, I put it up on pastebin ( http://pastebin.com/9LheZ6A1 ). The 'commit_key' I'd just added a few weeks ago, with no problems.

Now I update the schema:

$ doctrine orm:schema-tool:update --dump-sql
ALTER TABLE cloud ADD record_checksum VARCHAR(32) DEFAULT NULL;
$ doctrine orm:schema-tool:update --force
Updating database schema...
Database schema updated successfully!

I verified this field now exists in the DB table.

However, when I run a simple DQL query like this:

$dql =  "SELECT c.id AS id, c.commit_key AS key, c.record_checksum AS checksum ".
                "FROM Entity\\Cloud c WHERE c.commit_group = :commit_group";

I get the error:

 [Semantical Error] line 0, col 42 near 'record_checksum': Error: Class Entity\Cloud has no field or association named record_checksum, 

I've banged my head on the wall over this for a while now. I'm sure I'm overlooking something really stupid. Any help is greatly appreciated! -Nick

解决方案

Try to:

  1. Clear any cache that may contain the config or PHP code.
  2. Rename a field in case the first solution didn't work.

这篇关于Doctrine 2:错误:Class“.. \ ..”没有名为“...”的字段或关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆