doctrine/DoctrineMigrationsBundle

Migrations regenerates DROP CONSTRAINT and ADD the same CONSTRAINT

rusinowiczjakub opened this issue · 2 comments

I'm having a problem with migrations:diff constantly regen deleting and adding a foreign key in a table:

final class Version20230417120412 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE project.project DROP CONSTRAINT FK_D9574D85A76ED395');
        $this->addSql('ALTER TABLE project.project ADD CONSTRAINT FK_D9574D85A76ED395 FOREIGN KEY (user_id) REFERENCES account."user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE project.project DROP CONSTRAINT fk_d9574d85a76ed395');
        $this->addSql('ALTER TABLE project.project ADD CONSTRAINT fk_d9574d85a76ed395 FOREIGN KEY (user_id) REFERENCES account."user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
    }
}

I have cleaned the entire database and generated all migrations from scratch but still in each new migration, the code I have given above is generated.
This is what my mappings look like:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                    https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity
        name="CropinkApi\Domain\Model\Project"
        table="project"
        schema="project"
    >
        <indexes>
            <index name="project_id_idx" columns="id"/>
        </indexes>

        <id name="id" column="id" type="project_id"/>

        <embedded name="name" class="CropinkApi\Domain\ValueObject\ProjectName" use-column-prefix="false"/>
        <field name="feed" column="feed" type="feed" nullable="true"/>
        <field name="createdAt" column="created_at" type="cropink_date" />
        <field name="updatedAt" column="updated_at" type="cropink_date" />
        <field name="lastUpdateId" column="last_update_id" type="project_update_id" nullable="true"/>
        <field name="currentUpdateId" column="current_update_id" type="project_update_id" nullable="true"/>
        <field name="active" column="active" type="boolean"/>

        <many-to-one field="user" target-entity="CropinkApi\Domain\Model\User">
            <join-column name="user_id" referenced-column-name="id" nullable="false" />
        </many-to-one>
    </entity>

</doctrine-mapping>
Adi-18 commented

Exactly same to me.

        $this->addSql('ALTER TABLE CompetitionPersonen DROP FOREIGN KEY FK_CFE7FC3DA5955BB0');
        $this->addSql('DROP INDEX idx_cfe7fc3da5955bb0 ON CompetitionPersonen');
        $this->addSql('CREATE INDEX IDX_CFE7FC3D34DCD176 ON CompetitionPersonen (person)');
        $this->addSql('ALTER TABLE CompetitionPersonen ADD CONSTRAINT FK_CFE7FC3DA5955BB0 FOREIGN KEY (person) REFERENCES Personen (id)');

Have the same issue with "user" table