I have a simple Entity consisting of just one field "name":
/**
* @ORM\Table(name="gender")
* @ORM\Entity
* @codeCoverageIgnore
*/
class Gender
{
public const FEMALE = 'female';
public const MALE = 'male';
public const OTHER = 'other';
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=15, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private string $name;
public function getName(): string
{
return $this->name;
}
public function setName(string $name): Gender
{
$this->name = $name;
return $this;
}
}
For this class I try to generate fixtures and insert them into a sqlite db for testing:
use App\Entity\Gender; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager;
class GenderFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
$genders = [Gender::FEMALE, Gender::MALE, Gender::OTHER];
foreach ($genders as $genderName) {
echo $genderName . PHP_EOL;
$gender = (new Gender())
->setName($genderName);
$manager->persist($gender);
}
$manager->flush();
}
}
When I call
bin/console doctrine:fixtures:load --env=test
I get this:
female
male
other
In AbstractSQLiteDriver.php line 39:
An exception occurred while executing 'INSERT INTO gender (name) VALUES (null)':
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: gender.name
So as you can see there are the three strings I want to use as name. Why are they not used by the Fixture in the insert statement?
Symfony 4.4, PHP 7.4.1, Doctrine Fixtures 3.3.0