2016-09-23 5 views
-2

nullにすることはできません「整合性制約違反を:1048列 『ecriture_idは』 nullにすることはできません」:は、エンティティを永続:私はこのコードを使用すると、私はこのエラーを持っている

私は "$をコメント解除した場合this-> em-> persist($ ecriture) "それは本当です。私の "Produit" 実体はカスケードを持っているので、私は理解していない

を持続:

エンティティ "Produit":

class Produit 
{ 
    /** 
    * @ORM\OneToOne(targetEntity="LogicielBundle\Entity\Ecriture", inversedBy="gestionLocativeProduit", cascade={"persist"}) 
    * @ORM\JoinColumn(nullable=false) 
    */ 
    private $ecriture; 

    public function setEcriture(\LogicielBundle\Entity\Ecriture $ecriture) 
    { 
     $ecriture->setGestionLocativeProduit($this); 
     $this->ecriture = $ecriture; 
     // Similar problem if I add "$ecriture->setGestionLocativeProduit($this);" right here 
     return $this; 
    } 

    public function getEcriture() 
    { 
     return $this->ecriture; 
    } 

エンティティ "Ecriture":

class Ecriture 
{ 
    /** 
    * @ORM\OneToOne(targetEntity="LogicielBundle\Entity\GestionLocative\Produit", mappedBy="ecriture") 
    * @ORM\JoinColumn(nullable=true) 
    */ 
    private $gestionLocativeProduit; 

    public function setGestionLocativeProduit(\LogicielBundle\Entity\GestionLocative\Produit $gestionLocativeProduit) 
    { 
     $this->gestionLocativeProduit = $gestionLocativeProduit; 
     return $this; 
    } 

    public function getGestionLocativeProduit() 
    { 
     return $this->gestionLocativeProduit; 
    } 

答えて

0

私はいつも同じ問題を抱えていましたnデータベースに新しい列を追加しましたが、nullエラーにはなりません。

nullableを追加するのが本当であった場合は、twigのコントローラまたはフォームにrequired = true属性を追加することがほとんどでした。それゆえに、常に満たされなければなりませんでした。

関連する問題