Symfony教义迁移对继承表格错误的区别

时间:2019-03-06 07:58:43

标签: symfony doctrine-orm doctrine

我对继承的表使用doctrine:migrations:diff命令生成的差异存在问题。 我无法通过迁移迁移来生成这些表,但是直接使用SQL脚本即可。

这是父表的SQL脚本:

create table if not exists sensor
(
  id           integer    not null
    constraint sensor_pkey
    primary key,
  sensor_class integer
    constraint fk_bc8617b0ab0f4377
    references sensor_class,
  name         text,
  manufacturer text,
  status       text,
  mount        text,
  weight       numeric(10, 2) default NULL :: numeric,
  width        numeric(10, 2) default NULL :: numeric,
  height       numeric(10, 2) default NULL :: numeric,
  sensor_model integer,
  type         varchar(3) not null
);

这是一个继承表的SQL脚本:

create table if not exists tir
(
  no_px_height              integer,
  no_px_width               integer,
  bit_depth                 numeric(10, 2) default NULL :: numeric,
  cooled                    numeric(10, 2) default NULL :: numeric,
  radiometric               numeric(10, 2) default NULL :: numeric,
  single_shot_max_data_rage numeric(10, 2) default NULL :: numeric,
  detector_size_h           numeric(10, 2) default NULL :: numeric,
  detector_size_w           numeric(10, 2) default NULL :: numeric,
  fov_h                     numeric(10, 2) default NULL :: numeric,
  fov_w                     numeric(10, 2) default NULL :: numeric,
  focal_length              numeric(10, 2) default NULL :: numeric,
  band_width_min            numeric(10, 2) default NULL :: numeric,
  band_width_max            numeric(10, 2) default NULL :: numeric,
  min_time_between_images   numeric(10, 2) default NULL :: numeric
)
  inherits (sensor);

我还有其他表是从Sensor继承的,这些表在Sensor实体的判别图中表示。

这是Sensor实体:

/**
 * Sensor
 *
 * @ORM\Table(name="sensor")
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string", length=3)
 * @ORM\DiscriminatorMap({
 *     "TIR"="Tir",
 *     "RGB"="Rgb",
 *     "MLS"="Multispectral",
 *     "EOC"="VideoCamera"
 * })
 */
abstract class Sensor
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     */
    public $id;

    /**
     * @var string|null
     *
     * @ORM\Column(name="name", type="text", nullable=true)
     */
    public $name;

    /**
     * @var string|null
     *
     * @ORM\Column(name="manufacturer", type="text", nullable=true)
     */
    public $manufacturer;

    /**
     * @var int|null
     *
     * @ORM\Column(name="sensor_model", type="integer", nullable=true)
     */
    public $sensorModel;
others fields...

这是继承的实体之一:

/**
 * @ORM\Entity
 * @ORM\Table(name="tir")
 */
class Tir extends Sensor
{
    /**
     * @var int|null
     *
     * @ORM\Column(name="no_px_height", type="integer", nullable=true)
     */
    private $noPxHeight;

    /**
     * @var int|null
     *
     * @ORM\Column(name="no_px_width", type="integer", nullable=true)
     */
    private $noPxWidth;

    /**
     * @var float|null
     *
     * @ORM\Column(name="bit_depth", type="decimal", precision=10, scale=2, nullable=true)
     */
    private $bitDepth;
others fields.

仅不继承字段。

迁移差异输出:

$this->addSql('ALTER TABLE tir DROP sensor_class');
$this->addSql('ALTER TABLE tir DROP name');
$this->addSql('ALTER TABLE tir DROP manufacturer');
$this->addSql('ALTER TABLE tir DROP status');
$this->addSql('ALTER TABLE tir DROP mount');
$this->addSql('ALTER TABLE tir DROP weight');
$this->addSql('ALTER TABLE tir DROP width');
$this->addSql('ALTER TABLE tir DROP height');
$this->addSql('ALTER TABLE tir DROP sensor_model');
$this->addSql('ALTER TABLE tir DROP type');
$this->addSql('ALTER TABLE tir ADD CONSTRAINT FK_A68DD960BF396750     FOREIGN KEY (id) REFERENCES sensor (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE tir ADD PRIMARY KEY (id)');

如何防止这些差异?

0 个答案:

没有答案