Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations regenerates DROP CONSTRAINT and ADD the same CONSTRAINT #493

Open
rusinowiczjakub opened this issue Apr 17, 2023 · 2 comments
Open

Comments

@rusinowiczjakub
Copy link

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
Copy link

Adi-18 commented May 1, 2023

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)');

@vitagon
Copy link

vitagon commented Apr 21, 2024

Have the same issue with "user" table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants