Skip to content

Migrations regenerates DROP CONSTRAINT and ADD the same CONSTRAINT #493

Description

@rusinowiczjakub

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions