Tanto no código de renomear estudante quanto de apagar ele, da este erro na hora de executar:
PHP Warning: Undefined array key 1 in \bin\delete-student.php on line 9
PHP Fatal error: Uncaught Doctrine\ORM\Exception\MissingIdentifierField: The identifier id is missing for a query of Alura\Doctrine\Entity\Student in \vendor\doctrine\orm\src\Exception\MissingIdentifierField.php:15
Stack trace:
#0 \vendor\doctrine\orm\src\EntityManager.php(298): Doctrine\ORM\Exception\MissingIdentifierField::fromFieldAndClass()
#1 \bin\delete-student.php(9): Doctrine\ORM\EntityManager->find()
#2 {main}
thrown in \vendor\doctrine\orm\src\Exception\MissingIdentifierField.php on line 15
O código de apagar estudante está assim:
<?php
use Alura\Doctrine\Helper\EntityManagerCreator;
use Alura\Doctrine\Entity\Student;
require_once __DIR__ . '/../vendor/autoload.php';
$entityManager = EntityManagerCreator::createEntityManager();
$student = $entityManager->find(Student::class, $argv[1]);
$entityManager->remove($student);
$entityManager->flush();
E a entidade de estudante está assim:
<?php
namespace Alura\Doctrine\Entity;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\GeneratedValue;
#[Entity]
class Student {
#[Id]
#[GeneratedValue]
#[Column]
public readonly int $id;
public function __construct(
#[Column]
public readonly string $name
) {}
}
O que pode ser este problema?