Search code examples
phpormdoctrine-ormdql

Doctrine 2: Error: Class "..\.." has no field or association named "..."


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


Solution

  • 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.