title: Integrity constraint violation: 1048 Column 'gameHallID' cannot be null in Symfony One to Many Relationship
body: <p>I have two tables store and store_timings in which i would like to save store timings from mon to sun.I have created two entities Store.php and Store_timings.php </p>
  
  <blockquote>
    <p>Store.php
        
  </blockquote>
  
  <pre><code>namespace Test\BotBundle\Entity;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * Store
  *
  * @ORM\Table(name="store", indexes={@ORM\Index(name="idxReference", 
  columns={"reference"}), @ORM\Index(name="idxLounges", columns={"name", 
  "province", "loungePage"})})
  * @ORM\Entity
  */
  class Store
  {
  /**
   * @var integer
   *
   * @ORM\Column(name="storeID", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
  private $storeID;
  
  /**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=50, nullable=true)
   */
  private $name;
  
  /**
   * @var string
   *
   * @ORM\Column(name="openinghours", type="blob", length=65535, nullable=true)
   */
  private $openinghours;
  
  /**
   * @var string
   *
   * @ORM\Column(name="document", type="blob", length=65535, nullable=true)
   */
  private $document;
  
  /**
   * @var ArrayCollection
   * @ORM\OneToMany(targetEntity="Test\BotBundle\Entity\StoreTimings",mappedBy="gameHallOpeningHours",cascade={"persist"})
   */
  private $gameHallOpeningHours;
  
  /**
   * @var \DateTime
   *
   * @ORM\Column(name="addedTs", type="datetime", nullable=true)
   */
  private $addedts;
  
  /**
   * Store constructor.
   */
  public function __construct()
  {
      $this-&gt;gameHallOpeningHours = new ArrayCollection();
  }
  
  /**
   * @return int
   */
  public function getStoreId()
  {
      return $this-&gt;storeID;
  }
  
  /**
   * @param Store $storeId
   */
  public function setStoreId(Store $storeId)
  {
      $this-&gt;storeId = $storeId;
  }
  
  /**
   * @return string
   */
  public function getName()
  {
      return $this-&gt;name;
  }
  
  /**
   * @param string $name
   */
  public function setName($name)
  {
      $this-&gt;name = $name;
  }
  
  /**
   * @return string
   */
  public function getOpeninghours()
  {
      return $this-&gt;openinghours;
  }
  
  /**
   * @param string $openinghours
   */
  public function setOpeninghours($openinghours)
  {
      $this-&gt;openinghours = $openinghours;
  }
  
  /**
   * @return string
   */
  public function getDocument()
  {
      return $this-&gt;document;
  }
  
  /**
   * @param string $document
   */
  public function setDocument($document)
  {
      $this-&gt;document = $document;
  }
  
  /**
   * @return \DateTime
   */
  public function getAddedts()
  {
      return $this-&gt;addedts;
  }
  
  /**
   * @param \DateTime $addedts
   */
  public function setAddedts($addedts)
  {
      $this-&gt;addedts = $addedts;
  }
  
  
  /**
   * @return ArrayCollection | Store
   */
  public function getGameHallOpeningHours()
  {
      return $this-&gt;gameHallOpeningHours;
  }
  
  /**
   * @param array $gameHallOpeningHours
   */
  public function setGameHallOpeningHours(array $gameHallOpeningHours)
  {
      $this-&gt;gameHallOpeningHours = $gameHallOpeningHours;
  }
  
  
  
  }
  </code></pre>
  
  <blockquote>
    <p>StoreTimings.php
        
  </blockquote>
  
  <pre><code>namespace Test\BotBundle\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * StoreTimings
   *
   * @ORM\Table(name="store_timings")
   */
  class StoreTimings
  { 
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
   private $id;
  
  /**
   *
   * @ORM\ManyToOne(targetEntity="store",cascade={"persist"})
   * @ORM\JoinColumn(name="gameHallID", referencedColumnName="storeID")
   */
  private $gameHallID;
  
  /**
   * @var string
   *
   * @ORM\Column(name="day", type="string", length=11, nullable=true)
   */
  private $day;
  
  /**
   * @var string
   *
   * @ORM\Column(name="opening_hours", type="string", length=11, nullable=true)
   */
  private $openingHours;
  
  /**
   * @var string
   *
   * @ORM\Column(name="closing_hours", type="string", length=11, nullable=true)
   */
  private $closingHours;
  
  /**
   * @return int
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * @param int $id
   */
  public function setId($id)
  {
      $this-&gt;id = $id;
  }
  
  /**
   * @return int
   */
  public function getGameHallID()
  {
      return $this-&gt;gameHallID;
  }
  
  /**
   * @param int $gamehallid
   */
  public function setGamehallid($gamehallid)
  {
      $this-&gt;gameHallID = $gamehallid;
  }
  
  /**
   * @return string
   */
  public function getDay()
  {
      return $this-&gt;day;
  }
  
  /**
   * @param string $day
   */
  public function setDay($day)
  {
      $this-&gt;day = $day;
  }
  
  /**
   * @return string
   */
  public function getOpeningHours()
  {
      return $this-&gt;openingHours;
  }
  
  /**
   * @param string $openingHours
   */
  public function setOpeningHours($openingHours)
  {
      $this-&gt;openingHours = $openingHours;
  }
  
  /**
   * @return string
   */
  public function getClosingHours()
  {
      return $this-&gt;closingHours;
  }
  
  /**
   * @param string $closingHours
   */
  public function setClosingHours($closingHours)
  {
      $this-&gt;closingHours = $closingHours;
  }
  
  }
  </code></pre>
  
  <p>i am able to generate the forms containing fields from both the entities but while saving i am getting Integrity Constriant Violation.</p>
  
  <p>I have done too much of SO / googled a lot. Also i am newbie to Symfony.</p>
  
  <blockquote>
    <p>Also when i try to print before saving to the DB i get below object </p>
  </blockquote>
  
  <pre><code>Test\BotBundle\Entity\Store Object
  (
  [storeID:Test\BotBundle\Entity\Store:private] =&gt; 
  [name:Test\BotBundle\Entity\Store:private] =&gt; ergeg
  [address:Test\BotBundle\Entity\Store:private] =&gt; Rege
  [zip:Test\BotBundle\Entity\Store:private] =&gt; rger
  [city:Test\BotBundle\Entity\Store:private] =&gt; erg
  [province:Test\BotBundle\Entity\Store:private] =&gt; gerg
  [phone:Test\BotBundle\Entity\Store:private] =&gt; rg
  [reference:Test\BotBundle\Entity\Store:private] =&gt; 
  [email:Test\BotBundle\Entity\Store:private] =&gt; 
  [coords:Test\BotBundle\Entity\Store:private] =&gt; 
  [loungepage:Test\BotBundle\Entity\Store:private] =&gt; 1
  [hasvouchers:Test\BotBundle\Entity\Store:private] =&gt; 1
  [cashoutallowed:Test\BotBundle\Entity\Store:private] =&gt; 1
  [hasparking:Test\BotBundle\Entity\Store:private] =&gt; 1
  [hashotkeys:Test\BotBundle\Entity\Store:private] =&gt; 1
  [openinghours:Test\BotBundle\Entity\Store:private] =&gt; 
  [document:Test\BotBundle\Entity\Store:private] =&gt; 
  [gameHallOpeningHours:Test\BotBundle\Entity\Store:private] =&gt; Array
      (
          [0] =&gt; Test\BotBundle\Entity\StoreTimings Object
              (
                  [id:Test\BotBundle\Entity\StoreTimings:private] =&gt; 
                  [gameHallID:Test\BotBundle\Entity\StoreTimings:private] 
  =&gt; 
                  [day:Test\BotBundle\Entity\StoreTimings:private] =&gt; 1
                  [openingHours:Test\BotBundle\Entity\StoreTimings:private] =&gt; 
                  [closingHours:Test\BotBundle\Entity\StoreTimings:private] =&gt; 
              )
  
      )
  
      [addedts:Test\BotBundle\Entity\Store:private] =&gt; 
  )
  </code></pre>
  
  <blockquote>
    <p>StoreType.php</p>
  </blockquote>
  
  <pre><code>  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('name')
          -&gt;add('address')
          -&gt;add('zip')
          -&gt;add('city')
          -&gt;add('province')
          -&gt;add('phone')
          -&gt;add('loungepage')
          -&gt;add('hasvouchers')
          -&gt;add('cashoutallowed')
          -&gt;add('hasparking')
          -&gt;add('hashotkeys')
      ;
  
         $builder-&gt;add('store_id','collection',[
              'type' =&gt; 'store_timings',
              'property_path' =&gt; 'game_hall_opening_hours',
              'allow_add'    =&gt; true,
          ]); 
  
  
  }
  /**
   * @param OptionsResolver $resolver
   */
  public function configureOptions(OptionsResolver $resolver)
  {
      $resolver-&gt;setDefaults(array(
          'data_class' =&gt; Store::class,
      ));
  }
  </code></pre>
  
  <blockquote>
    <p>StoreTimingsType.php</p>
  </blockquote>
  
  <pre><code>class StoreTimingsType extends AbstractType
  {
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('day','choice',[
              'choices' =&gt; [
                  1=&gt;'Monday',
                  2=&gt;'Tuesday',
                  3=&gt;'Wednesday',
                  4=&gt;'Thursday',
                  5=&gt;'Friday',
                  6=&gt;'Saturday',
                  7=&gt;'Sunday'],
          ])
          -&gt;add('opening_hours')
          -&gt;add('closingHours');
  
  }
  
  public function setDefaultOptions(OptionsResolverInterface $resolver)
  {
      $resolver-&gt;setDefaults([
          'data_class' =&gt; StoreTimings::class,
      ]);
  }
  </code></pre>