原则不承认向原则实体(Symfony 2.6 标准)添加的列

Added columns to Doctrine Entity (Symfony 2.6 standard) are not recognized by doctrine

我的 symfony2 应用程序中有一个实体,它具有多个属性。它实现了 JSON 可序列化,因为实体上的所有工作都是在 javascript 端完成的,而且我定义了一个神奇的 setter 函数,因此我可以循环遍历 JSON我从客户端获取并立即设置我的所有属性。

Class定义:

   /**
   *@ORM\Entity
   *@ORM\Table(name="creature")
   */
    class Creature implements JsonSerializable {

非典型函数定义:

public function __set($name, $value) {
    $this->$name = $value;

    return $this;
}
public function jsonSerialize() {
  $json = array();
  foreach($this as $key => $value) {
    if($key != "attacks") {
      $json[$key] = $value;
    } else {
      $json[$key] = array();
      for($x = 0; $x < count($this->attacks); $x++) {
        $json[$key][$x] = array();
        $json[$key][$x]["attack"] = $this->attacks[$x]->getName();
        $json[$key][$x]["bonus"] = $this->attacks[$x]->getBonus();
        $json[$key][$x]["damage"] = $this->attacks[$x]->getDamage();
      }
    }
  }
  return $json;
}

在大多数情况下,该实体运行良好。除非我继续前进,否则我发现我需要再添加 3 列。所以,很自然地,我将它添加到我的实体 class:

  /**
   *ORM\Column(type="integer", nullable=true)
   */
  protected $experience;

  /**
   *ORM\Column(type="integer", nullable=true)
   */
  protected $cr;

  /**
   *ORM\Column(type="integer", nullable=true)
   */
  protected $proficiencybonus;

并试图 运行

php app/console generate:doctrine:entities AppBundle
php app/console doctrine:schema:update --force

除了两个命令都没有识别出我进行了任何更改。我尝试清除我的缓存(开发和生产)并从实体中删除我的自定义代码,但它仍然不会添加我的三个新列。我的下一个想法是完全重置我的数据库,但如果可以的话,我并不热衷于这样做。

有人有什么想法吗?

您似乎忘记了注释中的 @ :

/**
 *@ORM\Column(type="integer", nullable=true)
 */
protected $experience;

/**
 *@ORM\Column(type="integer", nullable=true)
 */
protected $cr;

/**
 *@ORM\Column(type="integer", nullable=true)
 */
protected $proficiencybonus;

我有类似的问题,我忘了添加:*@ORM\Entity注释。

这也会导致不添加/更新实体。