Nic*_*ngs 4 php orm dql doctrine-orm
在搜索时,我想出了许多有类似问题的人的结果,但它们总是与关联错误有关。我正在尝试向数据库中的表添加一个简单的文本字段,并且在我的一生中,我无法弄清楚这次有什么不同 - 当我之前多次都没有问题时。
我已经向 4 个不同的实体添加了一个“record_checksum”字段,但我将只使用一个,这里是为了简化示例。(所有 4 个都会发生相同的错误)。
这是我的 Entity\Cloud.php 文件的示例,在底部添加了“ record_checksum ”字段:
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;
Run Code Online (Sandbox Code Playgroud)
该类的其余部分是 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
Updating database schema...
Database schema updated successfully!
Run Code Online (Sandbox Code Playgroud)
我验证了这个字段现在存在于 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";
Run Code Online (Sandbox Code Playgroud)
我收到错误:
[Semantical Error] line 0, col 42 near 'record_checksum': Error: Class Entity\Cloud has no field or association named record_checksum,
Run Code Online (Sandbox Code Playgroud)
我已经有一段时间在这上面撞墙了。我确定我忽略了一些非常愚蠢的事情。任何帮助是极大的赞赏!-缺口
尝试: