Doctrine - 在创建新实体时将 $id 设置为 UUID 而不是 Integer

Doctrine - Set $id as UUID instead of Integer when creating new entity

我正在使用 Symfony 5.3 开发一个新项目。我正在使用此命令 bin/console make:entity 创建实体。

此向导自动创建一个实体,其中 $id 作为整数类型的主键。我更喜欢 UUID 而不是整数。

我应该如何更改设置以获得这样的实体?

谢谢

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;
    
     ...
}

没有选项可以在制作实体上设置生成的标识符策略。 您可以使用 php bin/console make:entity -h

查看所有可用选项

doctrine.yaml 文件中也没有配置来定义它。

为当前和下一个版本添加可能是一个很好的功能

要请求新功能,您可以创建新问题功能请求类型: https://github.com/symfony/symfony/issues/new/choose 您将需要一个 github 帐户