Symfony,继承实体和Doctrine迁移

3
在Symfony 5.0中,我使用通用的实体类来统一内部项目。我的通用实体(如Table)如下所示:

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\TableRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorMap({"generic_table": "App\Entity\Generic\Table", "table": "App\Entity\Table"})
 */
class Site
{
    //protected properties and public methods
}

以及继承的类:


use App\Entity\Generic\Table as GenericTable;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\TableRepository")
 */
class Table extends GenericTable
{
    //private properties and public methods
}

然而,执行此命令时:

php bin/console make:migration

它返回以下内容:
Table mybd.table already exists.

即使表格不存在。
有什么想法吗?我是否忘了一个ORM语句?

使用Discriminator时,不要在表上声明“DiscriminatorMap”(自动生成,参见文档,在页面上搜索“if no discriminator”)。毫无意义的是,父类知道所有子类。如果您的Table/Site类不应该独立存在,则可以将其定义为抽象类,并在其上使用MappedSuperclass注释。由于您的鉴别器映射导致**\ Table中出现重复的Table - rkeet
1个回答

0
一个引导:我们必须在@ORM\Table注释中定义不同的表名: @ORM\Table(name="generic_table") 适用于class Table @ORM\Table(name="table") 适用于class Table extends GenericTable 最后,它只在数据库中创建了一个generic_table表,并重新定义了该表上的约束。但我仍然遇到Repositories的问题...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接