Skip to content

Doctrine - Optional feature $id as UUID instead of Integer when creating new entity #1033

Closed as not planned
@skocdopolet

Description

@skocdopolet

Description

I am working on a new project in Symfony 5.3. I am using this command bin/console make:entity for creating entities.

This wizard automatically creates an entity with $id as primary key of type integer. I am prefering UUID instead of integer.

How I should change settings to get Entity like example?

Example

namespace App\Entity;

use App\Repository\EventRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;

/**

  • @Orm\Entity(repositoryClass=EventRepository::class)
    /
    class Event
    {
    /
    *

    • @Orm\Id
    • @Orm\Column(type="uuid", unique=true)
    • @Orm\GeneratedValue(strategy="CUSTOM")
    • @Orm\CustomIdGenerator(class=UuidGenerator::class)
      */
      private $id;

    ...
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions