У меня есть объект с уникальным ограничением:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Relaciones
*
* @ORM\Entity
* @ORM\Table(name="relaciones",uniqueConstraints={@ORM\UniqueConstraint(name="persona_relacion_unica_idx", columns={"id_persona_principal", "id_persona_relacionada"}, options={"where": "(isActive IS TRUE)"})})
*/
class Relaciones
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="relaciones_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var \AppBundle\Entity\Personas
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Personas")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_persona_principal", referencedColumnName="id")
* })
*/
private $personaPrincipal;
/**
* @var \AppBundle\Entity\Personas
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Personas")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_persona_relacionada", referencedColumnName="id")
* })
*/
private $personaRelacionada;
/**
* @var \DateTime $updated
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @var \DateTime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
}
и каждый раз, когда я обновляю базу данных, она вносит одинаковые изменения
# php bin/console doctrine:schema:update --dump-sql
The following SQL statements will be executed:
DROP INDEX persona_relacion_unica_idx;
ALTER TABLE relaciones ALTER observacion TYPE VARCHAR(255);
ALTER TABLE relaciones ALTER observacion DROP DEFAULT;
CREATE UNIQUE INDEX persona_relacion_unica_idx ON relaciones (id_persona_principal, id_persona_relacionada) WHERE (isActive IS TRUE);
# php bin/console doctrine:schema:update --force
Updating database schema...
2 queries were executed
[OK] Database schema updated successfully!
# php bin/console doctrine:schema:update --dump-sql
The following SQL statements will be executed:
DROP INDEX persona_relacion_unica_idx;
CREATE UNIQUE INDEX persona_relacion_unica_idx ON relaciones (id_persona_principal, id_persona_relacionada) WHERE (isActive IS TRUE);
Есть идеи?
UPDATE
# php bin/console doctrine:schema:validate
Mapping
-------
[OK] The mapping files are correct.
Database
--------
[ERROR] The database schema is not in sync with the current mapping file.