首页 > 解决方案 > Doctrine make:migration 在类名生成器上抛出错误

问题描述

我目前正在努力解决我的网络项目中的问题。

我通过“bin/console make:entity”命令创建了一个“凭证”实体,我想进行迁移以写入数据库。但是 Doctrine 抛出了一个奇怪的错误,我不知道如何解决它。谁能帮我?

Symfony 4.4.10 和 Doctrine 1.4

错误:

在 ClassNameGenerator.php 第 14 行:传递给 Doctrine\Migrations\Generator\ClassNameGenerator::generateClassName() 的参数 1 必须是字符串类型,给定 null,在 /var/www/skodanezajit/vendor/doctrine/migrations/lib/ 中调用Doctrine/Migrations/Tool s/Console/Command/DiffCommand.php 在第 139 行

凭证实体:

<?php

namespace App\Entity;

use App\Repository\VoucherRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=VoucherRepository::class)
 */
class Voucher
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $code;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateCreated;

    /**
     * @ORM\Column(type="datetime")
     */
    private $lastsTo;

    /**
     * @ORM\Column(type="integer")
     */
    private $value;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    private $used;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getDateCreated(): ?\DateTimeInterface
    {
        return $this->dateCreated;
    }

    public function setDateCreated(\DateTimeInterface $dateCreated): self
    {
        $this->dateCreated = new \DateTime('now');

        return $this;
    }

    public function getLastsTo(): ?\DateTimeInterface
    {
        return $this->lastsTo;
    }

    public function setLastsTo(\DateTimeInterface $lastsTo): self
    {
        $this->lastsTo = new \DateTime('now +6 months');

        return $this;
    }

    public function getValue(): ?int
    {
        return $this->value;
    }

    public function setValue(int $value): self
    {
        $this->value = $value;

        return $this;
    }

    public function getUsed(): ?bool
    {
        return $this->used;
    }

    public function setUsed(?bool $used): self
    {
        $this->used = $used;

        return $this;
    }
}

非常感谢!

标签: phpsymfonydoctrine-orm

解决方案


错误来自不存在的迁移文件夹。

尝试将其添加到您的 config/packages/doctrine_migrations.yaml 中:

doctrine_migrations:
    migrations_paths:
        DoctrineMigrations: 'src/Migrations'

如果不存在,则创建 src/Migrations 文件夹。


推荐阅读