3

我尝试在实体中添加一个 cahmps。我有这个代码:

/**
* @var integer $colorevent
* @ORM\Column(name="colorevent", type="integer")
*/
private $colorevent;

/**
* Get colorevent
* @return integer 
*/ 
public function getColorevent()
{
    return $this->colorevent;
}

/**
* Set colorevent
* @return integer 
*/
public function setColorevent($colorevent)
{
    return $this->colorevent = $colorevent ;
}

我运行这些命令:

php app/console doctrine:schema:update
php app/console doctrine:schema:update --dump-sql
php app/console doctrine:schema:update --force

呈现此消息:

没有更新 yopur 数据库的内容已与当前实体元数据同步

如何在实体中添加字段?

4

3 回答 3

2

第一次是如何生成实体类的?

如果实体文件是通过生成的,doctrine:generate:entities那么您需要做的是:

  1. 更新Resources/config/doctrine/XXXXXXXXX其中 xxxx 是实体名称。
  2. 运行app/console doctrine:generate:entity。这将重新生成 php 实体文件,以及私有属性 getter 和 setter。
  3. 运行php app/console doctrine:schema:update和更新数据库

根据您使用的格式(我使用的是 yml),可能会有一些变化,但最重要的是doctrine:schema:update需要找到当前和缓存(元数据)实体对象之间的变化。

于 2013-01-19T22:45:24.923 回答
1

每个实体都必须有Entity注解

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class MyEntity
{
    // some code
}

我还建议使用提供的控制台工具来创建实体。

app/console doctrine:generate:entity

更多信息请阅读官方书籍(Doctrine , Propel)。

于 2012-06-19T10:52:34.867 回答
0

如果您使用其他两个答案中描述的 yaml 或注释,则可以使用教义命令。但是该命令必须包含实体名称:

php app/console doctrine:generate:entities AcmeMyBundle:Customer
于 2014-04-20T15:50:47.820 回答