title: Symfony3 "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'catId' cannot be null "
body: <p>I'm trying to save data with ManyToOne relations in a DataFixtures class. And I get this error on saving data.</p>
  
  <p>Please, help me.</p>
  
  <p>Sources:</p>
  
  <p><strong>Entity/DealsCategory.php:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * DealsCategory
   *
   * @ORM\Table(name="deals_category")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\DealsCategoryRepository")
   */
  class DealsCategory
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="alias", type="string", length=50, nullable=true)
       */
      private $alias;
  
      /**
       * @ORM\OneToMany(targetEntity="DealsCategoryLang", mappedBy="category")
       */
      protected $categoryLang;
  
      /**
       * @return mixed
       */
      public function getCategoryLang()
      {
          return $this-&gt;categoryLang;
      }
  
      /**
       * @param DealsCategoryLang $categoryLang
       */
      public function setCategoryLang(DealsCategoryLang $categoryLang = null)
      {
          $this-&gt;categoryLang = $categoryLang;
      }
  
      /**
       * @param DealsCategoryLang $categoryLang
       */
      public function setOneCategoryLang(DealsCategoryLang $categoryLang)
      {
          $this-&gt;categoryLang[] = $categoryLang;
      }
  
      /**
       * DealsCategory constructor.
       */
      public function __construct()
      {
          $this-&gt;categoryLang = new ArrayCollection();
      }
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set alias
       *
       * @param string $alias
       *
       * @return DealsCategory
       */
      public function setAlias($alias)
      {
          $this-&gt;alias = $alias;
  
          return $this;
      }
  
      /**
       * Get alias
       *
       * @return string
       */
      public function getAlias()
      {
          return $this-&gt;alias;
      }
  }
  </code></pre>
  
  <p><strong>Entity/DealsCategoryLang.php:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * DealsCategoryLang
   *
   * @ORM\Table(name="deals_category_lang")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\DealsCategoryLangRepository")
   */
  class DealsCategoryLang
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var int
       *
       * @ORM\Column(name="catId", type="integer")
       */
      private $catId;
  
      /**
       * @var string
       *
       * @ORM\Column(name="lang", type="string", length=10)
       */
      private $lang;
  
      /**
       * @var string
       *
       * @ORM\Column(name="title", type="string", length=70)
       */
      private $title;
  
      /**
       * @ORM\ManyToOne(targetEntity="DealsCategory", inversedBy="categoryLang", cascade={"persist"})
       * @ORM\JoinColumn(name="catId", referencedColumnName="id")
       *
       */
      protected $category;
  
      /**
       * Get id
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set catId
       *
       * @param integer $catId
       *
       * @return DealsCategoryLang
       */
  //    public function setCatId($catId)
  //    {
  //        $this-&gt;catId = $catId;
  //
  //        return $this;
  //    }
  
      /**
       * Get catId
       *
       * @return int
       */
      public function getCatId()
      {
          return $this-&gt;catId;
      }
  
      /**
       * Set lang
       *
       * @param string $lang
       *
       * @return DealsCategoryLang
       */
      public function setLang($lang)
      {
          $this-&gt;lang = $lang;
  
          return $this;
      }
  
      /**
       * Get lang
       *
       * @return string
       */
      public function getLang()
      {
          return $this-&gt;lang;
      }
  
      /**
       * Set title
       *
       * @param string $title
       *
       * @return DealsCategoryLang
       */
      public function setTitle($title)
      {
          $this-&gt;title = $title;
  
          return $this;
      }
  
      /**
       * Get title
       *
       * @return string
       */
      public function getTitle()
      {
          return $this-&gt;title;
      }
  }
  </code></pre>
  
  <p><strong>DataFixtures/ORM/LoadCategories.php</strong></p>
  
  <pre><code>&lt;?php
  namespace AppBundle\DataFixtures\ORM;
  
  
  use AppBundle\Entity\DealsCategory;
  use AppBundle\Entity\DealsCategoryLang;
  use Doctrine\Common\DataFixtures\FixtureInterface;
  use Doctrine\Common\Persistence\ObjectManager;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  use Symfony\Component\DependencyInjection\ContainerInterface;
  
  class LoadCategories implements FixtureInterface, ContainerAwareInterface
  {
  
      private $container;
      /**
       * Load data fixtures with the passed EntityManager
       *
       * @param ObjectManager $manager
       */
      public function load(ObjectManager $manager)
      {
          $category = new DealsCategory();
          $categoryLang = new DealsCategoryLang();
          $categoryLang-&gt;setLang('en');
          $categoryLang-&gt;setTitle('Food and Drinks');
          $category-&gt;setOneCategoryLang($categoryLang);
  
          $manager-&gt;persist($category);
          $manager-&gt;persist($categoryLang);
          $manager-&gt;flush();
      }
  
      public function setContainer(ContainerInterface $container = null)
      {
          $this-&gt;container = $container;
      }
  }
  </code></pre>
  
  <p>I've tried it in different ways, but it's still not working. Tell me please, what i am doing wrong?</p>
  
  <p><strong>UPD:</strong>
  my errors are:</p>
  
  <blockquote>
    <p>[Doctrine\DBAL\Exception\NotNullConstraintViolationException]<br>
      An exception occurred while executing 'INSERT INTO deals_category_lang (catId, lang, title) VALUES (?, ?, ?)' with params [null, "en", "Food and Drinks"]:<br>
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'catId' cannot be null                                                                         </p>
    
    <p>[Doctrine\DBAL\Driver\PDOException]<br>
      SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'catId' cannot be null  </p>
    
    <p>PDOException]<br>
      SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'catId' cannot be null </p>
  </blockquote>
  
  <p>I am running the fixtures through the command line:</p>
  
  <pre><code>php bin/console doctrine:fixtures:load --append 
  </code></pre>