dbal icon indicating copy to clipboard operation
dbal copied to clipboard

Foreign key name change not picked up by schema comperator

Open achterin opened this issue 9 months ago • 0 comments

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; }

achterin avatar May 07 '24 09:05 achterin