0

In my Symfony 6 project, I am trying to load a fixture:

 /**
 * @param ObjectManager $manager
 */
public function load(ObjectManager $manager): void
{
    $manager1 = $manager;
    $manager1->persist($this->persistCompanyOne());
    $manager1->flush();
}

private function persistCompanyOne(): Company
{
    $company = new Company();
    $company->setCompanyName('Company One');
    return $company;
}

And my Company entity:

/**
 * @ORM\Column(type="string", length=180, nullable=false)
 */
private string $companyName;

 /**
 * @return string
 */
 public function getCompanyName(): string
 {
   return $this->name;
 }

   /**
     * @param mixed
     * @return Company
     */
    public function setCompanyName(string $name): Company
    {
        $this->name = $name;
        return $this;
    }

When running php bin/console doctrine:fixtures:load I get an error:

 Integrity constraint violation: 1048 Column 'company_name' cannot be null

Can not figure out what can be the problem? it's pretty straightforward..

keymon
  • 11
  • 2
  • Well, your private variable is $companyName. In your model/entity method setCompanyName, you then set some other variable $this->name. Of course you only have provided part of the entity but it looks like there's a disconnect there. If it's $companyName, then your set/get should reference `$this->companyName` – gview May 14 '22 at 05:40
  • Obvious mistake. Thanks! @gview – keymon May 14 '22 at 05:43

0 Answers0