title: Why is my cascade not working? - Integrity constraint violation
body: <p>I have an parent and child entities, parent being an image, and child being a vote for the image</p>
  
  <pre><code>class Image {
  
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
      /**
       * @ORM\Column(type="string", length=255, name="file_name")
       * @var string $fileName
       */
      protected $fileName;
  
      /**
       * @ORM\Column(type="string", length=255, name="title", nullable=true)
       * @var string $title
       */
      protected $title = null;
  
      /**
       * @ORM\Column(type="string", length=255, name="author", nullable=true)
       * @var string $author
       */
      protected $author = null;
  
      /**
       * @ORM\Column(type="datetime", name="upload_at")
       */
      protected $uploadDate;
  
      /**
       * @ORM\Column(type="boolean", name="in_pool")
       */
      protected $inPool;
  
      /**
      * One image has many votes
      * @ORM\OneToMany(targetEntity="Vote", mappedBy="image")
      */
      private $votes;
  </code></pre>
  
  <p>Child:</p>
  
  <pre><code>class Vote
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
      /**
       * @ORM\ManyToOne(targetEntity="Image", inversedBy="votes")
       * @ORM\JoinColumn(onDelete="CASCADE")
       */
      protected $image;
  
      /**
       * @ORM\Column(type="datetime", name="date")
       */
      protected $date;
  
      /**
       * This is internal variable, it does not have to be mapped into database field
       * @var int Counter of votes for an Image
       */
      private $counter;
  </code></pre>
  
  <p>As you can see I have the <code>@ORM\JoinColumn(onDelete="CASCADE")</code> set in the entity.</p>
  
  <p>However when I try to remove an image which has votes I get this:</p>
  
  <blockquote>
    <p>An exception occurred while executing 'DELETE FROM image WHERE id = ?'
    with params [24]:</p>
    
    <p>SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or
    update a parent row: a foreign key constraint fails (<code>konkurs</code>.<code>vote</code>,
    CONSTRAINT <code>FK_5A1085643DA5256D</code> FOREIGN KEY (<code>image_id</code>) REFERENCES
    <code>image</code> (<code>id</code>))</p>
  </blockquote>
  
  <p>The code used to delete an image based on id looks like this:</p>
  
  <pre><code>/**
  * @Route("/admin/removeimage/{id}", name="admin-remove-image")
  */
  public function adminRemoveImage($id)
  {
  
      $em = $this-&gt;getEm();
      $image = $em-&gt;getRepository('AppBundle:Image')-&gt;findOneById($id);
      $fileName = $image-&gt;getFileName();
  
      $em-&gt;remove($image);
      $em-&gt;flush();
  
      unlink('uploads/'.$fileName);
      unlink('media/cache/my_thumb/uploads/'.$fileName);
  
      return $this-&gt;redirectToRoute('admin-panel');
  }
  </code></pre>
  
  <hr>
  
  <p>Could anyone tell me why does this relation keep failing?</p>
  
  <p><strong>UPDATE</strong>
  Here is the output of using <code>SHOW CREATE TABLE vote</code></p>
  
  <blockquote>
    <p>| vote  | CREATE TABLE <code>vote</code> (   <code>id</code> int(11) NOT NULL
    AUTO_INCREMENT,   <code>date</code> datetime NOT NULL,   <code>image_id</code> int(11)
    DEFAULT NULL,   PRIMARY KEY (<code>id</code>),   KEY <code>IDX_5A1085643DA5256D</code>
    (<code>image_id</code>),   CONSTRAINT <code>FK_5A1085643DA5256D</code> FOREIGN KEY
    (<code>image_id</code>) REFERENCES <code>image</code> (<code>id</code>) ) ENGINE=InnoDB
    AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |</p>
  </blockquote>