phpsymfonyormdoctrine

Symfony - Undefined type 'Doctrine\ORM\Mapping\Entity


I got many errors similar to this in topic after created entities. Dont't know why cuz use tag seems correct. Using symfony 6.1.

Here is my model:

    namespace App\Entity;

    use App\Repository\MovieRepository;
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use Doctrine\ORM\Mapping as ORM;

    #[ORM\Entity(repositoryClass: MovieRepository::class)]
    class Movie
    {
      #[ORM\Id]
      #[ORM\GeneratedValue]
      #[ORM\Column(type: 'integer')]
      private $id;
    }

Solution

  • Instead of this

    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity(repositoryClass: MovieRepository::class)]
    class Movie
    {
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private $id;
    

    try that

    use Doctrine\ORM\Mapping\Column;
    use Doctrine\ORM\Mapping\Entity;
    use Doctrine\ORM\Mapping\GeneratedValue;
    use Doctrine\ORM\Mapping\Id;
    
    #[Entity(repositoryClass: MovieRepository::class)]
    class Movie
    {
        #[Id, GeneratedValue, Column(type: 'integer')]
        private int $id;