Erro de SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: Student.id
Código do arquivo insert-student.php
<?php
use Alura\Doctrine\Entity\Student; use Alura\Doctrine\Helper\EntityManagerCreator;
require_once DIR . '/../vendor/autoload.php';
$entityManager = EntityManagerCreator::createEntityManger();
$student = new Student(name: 'Fulano'); $entityManager->persist($student);
//Mandar tudo que o entityManager está monitorando e envio de uma vez para o banco $entityManager->flush();
código da entidade <?php
namespace Alura\Doctrine\Entity;
use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\GeneratedValue; use Doctrine\ORM\Mapping\Id;
#[Entity] class Student {
#[Id]
#[GeneratedValue]
#[Column]
private int $id;
public function __construct(
#[Column]
public string $name
) {
}
}