mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
One-To-One relationships with missing unique index causes invalid drop index on database diff #6922
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jackbentley on GitHub (Jan 31, 2022).
Bug Report
Summary
Bug was experienced while using PostgreSQL.
One-to-one relationships are expected to have a unique index.
https://github.com/doctrine/orm/blob/2.11.x/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L1893
When running
doctrine:schema:update, ORM will create an expected table schema with a unique index namedUNIQ_.https://github.com/doctrine/orm/blob/2.11.x/lib/Doctrine/ORM/Tools/SchemaTool.php#L745
When generating a table object from current schema, an index is always added for all FKs which is non-unique and with the prefix
IDX_. This isn't correct for One-To-One relations which will have a unique index prefixed withUNIQ_.https://github.com/doctrine/dbal/blob/3.3.x/src/Schema/Table.php#L578-L592
In my particular case, the table existed, a FK was present for the relation, but an index was not.
Current behaviour
This causes a "phantom" drop index. The code thinks the index exists in the database when it does not. The index is not present in the expected schema and is told to be dropped.
Expected behaviour
The drop index shouldn't be outputted
How to reproduce
doctrine:schema:createdoctrine:schema:update@beberlei commented on GitHub (Feb 2, 2022):
Just use Many to One if you don't want the unique index. That is the semantical difference between them.
@jackbentley commented on GitHub (Feb 2, 2022):
@beberlei I think you might've misunderstood. I want the unique index. It's expected. The schema update is trying to delete a non-unique index that doesn't exist before adding the expected unique index.