Doctrine 2 OneToMany Cascade SET NULL

前端 未结 1 1025
南旧
南旧 2020-12-01 03:59

The error

Cannot delete or update a parent row: a foreign key constraint fails.

The classes

class Teacher {

    /**
     *@ORM\\OneToMan         


        
相关标签:
1条回答
  • 2020-12-01 04:40

    You should add the option onDelete="SET NULL" in the annotation of your entity Publication like this:

    class Publication
    {
        /**
        * @ORM\ManyToOne(targetEntity="Teacher", inversedBy="publications")
        * @ORM\JoinColumn(name="teacher_id", referencedColumnName="id", onDelete="SET NULL")
        */
        protected $teacher;
    }
    

    Cheers!

    0 讨论(0)
提交回复
热议问题