在搜索时,我发现了许多有类似问题的人的结果,但它们总是与关联错误有关。我正在尝试将一个简单的文本字段添加到数据库中的表中,但在我的一生中,我无法弄清楚这次有什么不同 - 当我以前多次这样做时没有出现任何问题。
我已将“record_checksum”字段添加到 4 个不同的实体,但我将仅使用一个,此处是为了简化示例。 (所有 4 个都会发生同样的错误)。
这是我的 Entity\Cloud.php 文件的示例,其中包含 '记录校验和' 字段添加在底部:
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;
类的其余部分是 getter/setter 方法,所以我将省略它。要查看整个实体文件,我将其放在 Pastebin 上(http://pastebin.com/9LheZ6A1 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
Updating database schema...
Database schema updated successfully!
我验证了该字段现在存在于数据库表中。
但是,当我运行如下简单的 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";
我收到错误:
[Semantical Error] line 0, col 42 near 'record_checksum': Error: Class Entity\Cloud has no field or association named record_checksum,
我已经为此把头撞在墙上有一段时间了。我确信我忽略了一些非常愚蠢的事情。任何帮助是极大的赞赏!
-缺口