【发布时间】:2020-11-12 04:15:05
【问题描述】:
我目前正在努力解决我的网络项目的问题。
我通过“bin/console make:entity”命令创建了一个“凭证”实体,我想进行迁移以写入数据库。但是 Doctrine 抛出了一个奇怪的错误,我不知道如何解决它。谁能帮帮我?
Symfony 4.4.10 和 Doctrine 1.4
错误:
在 ClassNameGenerator.php 第 14 行: 参数 1 传递给 Doctrine\Migrations\Generator\ClassNameGenerator::generateClassName() 必须是字符串类型,给定 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;
}
}
非常感谢!
【问题讨论】:
-
您之前是否生成过迁移,而这只是这个类的问题?你在用什么命令?你的迁移配置是什么?
-
是的,我已经创建了一个实体,一切都很顺利。这是第一次发生类似的事情。我使用了“make:entity”,然后使用了“make:migration”,因为在我当前的本地环境中没有迁移。我的迁移配置都被评论了,我认为“symfony/flex”会处理这个问题。这会是问题吗?
-
我没有看到这个实体有什么奇怪的地方。根据迁移包的文档,你应该有 config 和 flex 如果它还没有到位,应该安装它 symfony.com/doc/master/bundles/DoctrineMigrationsBundle/… 。例如,至少需要一个 migrations_paths。我不知道为什么它被你注释掉了。
-
我无法重现我这边的错误。绝望的建议:你试过清除缓存吗?你做了作曲家更新吗?在 Doctrine Migrations Diff 命令期间似乎失败了。您是否尝试直接运行
php bin/console doctrine:migrations:diff而不是php bin/console make:migration?
标签: php symfony doctrine-orm