title: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
body: <p>I did my database using Wampserver and for the relations i used the casdace and i did the reverse engeenering so ..i can't delete a related object </p>
  
  <p>this is my entities</p>
  
  <p>1rst :</p>
  
  <pre><code>/**
   * Voiture
   *
   * @ORM\Table(name="voiture")
   * @ORM\Entity
   */
  class Voiture
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id_voiture", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      public $idVoiture;
  
      /**
       * @var string
       *
       * @ORM\Column(name="immatricule", type="string", length=50, nullable=false)
       */
      private $immatricule;
  
      /**
       * @var string
       *
       * @ORM\Column(name="marque", type="string", length=20, nullable=false)
       */
      private $marque;
  
      /**
       * @var string
       *
       * @ORM\Column(name="modele", type="string", length=20, nullable=false)
       */
      private $modele;
  
      /**
       * @var string
       *
       * @ORM\Column(name="typecarburant", type="string", length=20, nullable=false)
       */
      private $typecarburant;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="nbcheveaux", type="integer", nullable=false)
       */
      private $nbcheveaux;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="datemarche", type="date", nullable=false)
       */
      private $datemarche;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="nbr_place", type="integer", nullable=false)
       */
      private $nbrPlace;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id_user", type="integer", nullable=true)
       */
      private $idUser;
  
      /**
       * @return int
       */
      public function getIdVoiture()
      {
          return $this-&gt;idVoiture;
      }
  
      /**
       * @param int $idVoiture
       */
      public function setIdVoiture($idVoiture)
      {
          $this-&gt;idVoiture = $idVoiture;
      }
  
      /**
       * @return string
       */
      public function getImmatricule()
      {
          return $this-&gt;immatricule;
      }
  
      /**
       * @param string $immatricule
       */
      public function setImmatricule($immatricule)
      {
          $this-&gt;immatricule = $immatricule;
      }
  
      /**
       * @return string
       */
      public function getMarque()
      {
          return $this-&gt;marque;
      }
  
      /**
       * @param string $marque
       */
      public function setMarque($marque)
      {
          $this-&gt;marque = $marque;
      }
  
      /**
       * @return string
       */
      public function getModele()
      {
          return $this-&gt;modele;
      }
  
      /**
       * @param string $modele
       */
      public function setModele($modele)
      {
          $this-&gt;modele = $modele;
      }
  
      /**
       * @return string
       */
      public function getTypecarburant()
      {
          return $this-&gt;typecarburant;
      }
  
      /**
       * @param string $typecarburant
       */
      public function setTypecarburant($typecarburant)
      {
          $this-&gt;typecarburant = $typecarburant;
      }
  
      /**
       * @return int
       */
      public function getNbcheveaux()
      {
          return $this-&gt;nbcheveaux;
      }
  
      /**
       * @param int $nbcheveaux
       */
      public function setNbcheveaux($nbcheveaux)
      {
          $this-&gt;nbcheveaux = $nbcheveaux;
      }
  
      /**
       * @return \DateTime
       */
      public function getDatemarche()
      {
          return $this-&gt;datemarche;
      }
  
      /**
       * @param \DateTime $datemarche
       */
      public function setDatemarche($datemarche)
      {
          $this-&gt;datemarche = $datemarche;
      }
  
      /**
       * @return int
       */
      public function getNbrPlace()
      {
          return $this-&gt;nbrPlace;
      }
  
      /**
       * @param int $nbrPlace
       */
      public function setNbrPlace($nbrPlace)
      {
          $this-&gt;nbrPlace = $nbrPlace;
      }
  
      /**
       * @return int
       */
      public function getIdUser()
      {
          return $this-&gt;idUser;
      }
  
      /**
       * @param int $idUser
       */
      public function setIdUser($idUser)
      {
          $this-&gt;idUser = $idUser;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>2end</p>
  
  <pre><code>/**
   * Assurance
   *
   * @ORM\Table(name="assurance", indexes={@ORM\Index(name="id_carnet", columns={"id_voiture"})})
   * @ORM\Entity
   */
  class Assurance
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id_assurance", type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $idAssurance;
  
      /**
       * @var \DateTime
       *
       * @ORM\Column(name="date", type="date", nullable=false)
       */
      private $date;
  
      /**
       * @var integer
       *
       * @ORM\Column(name="valeur", type="integer", nullable=false)
       */
      private $valeur;
  
      /**
       * @var string
       *
       * @ORM\Column(name="assurant", type="string", length=255, nullable=false)
       */
      private $assurant;
  
      /**
       * @var \Voiture
       *
       * @ORM\ManyToOne(targetEntity="Voiture")
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="id_voiture", referencedColumnName="id_voiture")
       * })
       */
      private $idVoiture;
  
      /**
       * @return int
       */
      public function getIdAssurance()
      {
          return $this-&gt;idAssurance;
      }
  
      /**
       * @param int $idAssurance
       */
      public function setIdAssurance($idAssurance)
      {
          $this-&gt;idAssurance = $idAssurance;
      }
  
      /**
       * @return \DateTime
       */
      public function getDate()
      {
          return $this-&gt;date;
      }
  
      /**
       * @param \DateTime $date
       */
      public function setDate($date)
      {
          $this-&gt;date = $date;
      }
  
      /**
       * @return int
       */
      public function getValeur()
      {
          return $this-&gt;valeur;
      }
  
      /**
       * @param int $valeur
       */
      public function setValeur($valeur)
      {
          $this-&gt;valeur = $valeur;
      }
  
      /**
       * @return string
       */
      public function getAssurant()
      {
          return $this-&gt;assurant;
      }
  
      /**
       * @param string $assurant
       */
      public function setAssurant($assurant)
      {
          $this-&gt;assurant = $assurant;
      }
  
      /**
       * @return \Voiture
       */
      public function getIdVoiture()
      {
          return $this-&gt;idVoiture;
      }
  
      /**
       * @param \Voiture $idVoiture
       */
      public function setIdVoiture($idVoiture)
      {
          $this-&gt;idVoiture = $idVoiture;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>and delete action in controller :</p>
  
  <pre><code>public function deleteVAction($id)
  {
    $em = $this-&gt;getDoctrine()-&gt;getManager();
    $voiture= $em-&gt;getRepository('DataBundle:Voiture')-&gt;findOneBy(array('idVoiture'=&gt;$id)) ;
    $em-&gt;remove($voiture);
    $em-&gt;flush();
  
    return $this-&gt;redirectToRoute('User_affiche_voiture') ;
  }
  </code></pre>