Symfony2 ondelete设置Null

bra*_*990 1 php constraints foreign-keys symfony symfony-2.5

我是symfony2的新手,我开始了一个博客项目.该项目有两个实体,一个是posts(Noticia),另一个是comments(Comentario).我需要删除一个帖子,但我不能因为与评论的关系.

这是我的属性:

/**
 * @ORM\ManyToOne(targetEntity="Noticia", inversedBy="comentarios", onDelete="SET NULL")
 * @ORM\JoinColumn(name="noticia_id", referencedColumnName="id")
 */
private $noticia;
Run Code Online (Sandbox Code Playgroud)
/**
 * @ORM\OneToMany(targetEntity="Comentario", mappedBy="noticia")
 */
private $comentarios = array();
Run Code Online (Sandbox Code Playgroud)

我尝试放,onDelete="SET NULL"但是当我用doctrine更新我的数据库时:php app/console doctrine:schema:update --force我收到了这个错误:

The annotation @ORM\ManyToOne declared on property Noticia 
Bundle\Entity\Comentario\::$noticia does not have a property named "onDelete".
Avaible properties: targetEntity, cascade, fetch, inversedBy
Run Code Online (Sandbox Code Playgroud)

tho*_*fek 7

我相信onDelete ="SET NULL"应该是JoinColumn注释的一部分,而不是ManyToOne注释.

  • 另外,进行此更改后,请务必更新您的数据库架构。 (2认同)