Skip to content

Foreign key name change not picked up by schema comperator #6390

Closed
@achterin

Description

Bug Report

Q A
Version 3.8.4

Summary

I had created a migration via the symfony command doc:mig:diff early in development that created a new table and a new foreign key constraint to an already existing table. Later I must have changed something that influenced the foreign key name generation because if i delete the constraint now and create a new migration, it has a different name.
Old FK name: FK_E19D9AD24A7A78F6
New FK name: FK_E19D9AD2491C2540

Current behaviour

I would expect doctrine to pick up on that change and drop the old foreign key and create a new one but that isn't the case - it just gets ignored. This is due to Schema/Comperator.php:diffForeignKey() not checking for that name change. This function just checks if the foreign key columns, tables or actions changed.

How to reproduce

Rename an existing foreign key constraint and create a table diff.

Expected behaviour

The comperator should notice the foreign change and therefore drop the "orphaned" key and create a new one with the correct name.

Proposed change

Adding the following lines to the diffForeignKey() function will fix the issue:
if (strtolower($key1->getName()) !== strtolower($key2->getName())) { return true; }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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