[PR #11314] Fix SchemaTool::getSchemaFromMetadata() uniqueConstraint without a predefined name #12934

Closed
opened 2026-01-22 16:15:38 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/11314

State: closed
Merged: Yes


Bug Report

Q A
BC Break no
Version 3.0.x

Summary

SchemaTool can't correctly read a UniqueConstraint when it doesn't have a name specified.

Current behavior

If a unique constraint is specified for a table without a defined name i.e.: #[ORM\UniqueConstraint(fields: ['field', 'anotherField'])], the reading fails due to a type missmatch here. In such a case the $indexName is an integer but it should be null. This is correctly applied here

How to reproduce

Add a #[ORM\UniqueConstraint(fields: ['field', 'anotherField'])] to any entity and try to dump SQL. You will get

In Index.php line 42:
                                                                                                                                                                                          
  Doctrine\DBAL\Schema\Index::__construct(): Argument #1 ($name) must be of type ?string, int given, called in vendor/doctrine/orm/src/Tools/SchemaTool.php on line 340

Expected behavior

The unique constraint should be loaded correctly and a unique name should be generated for it automatically.

**Original Pull Request:** https://github.com/doctrine/orm/pull/11314 **State:** closed **Merged:** Yes --- ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 3.0.x #### Summary SchemaTool can't correctly read a UniqueConstraint when it doesn't have a name specified. #### Current behavior If a unique constraint is specified for a table without a defined name i.e.: `#[ORM\UniqueConstraint(fields: ['field', 'anotherField'])]`, the reading fails due to a type missmatch [here](https://github.com/doctrine/orm/blob/2a250b5814de192a23438c0a43e15da7e77890a7/src/Tools/SchemaTool.php#L340). In such a case the `$indexName` is an integer but it should be null. This is correctly applied [here](https://github.com/doctrine/orm/blob/2a250b5814de192a23438c0a43e15da7e77890a7/src/Tools/SchemaTool.php#L349) #### How to reproduce <!-- Provide steps to reproduce the bug. If possible, also add a code snippet with relevant configuration, entity mappings, DQL etc. Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> Add a `#[ORM\UniqueConstraint(fields: ['field', 'anotherField'])]` to any entity and try to dump SQL. You will get ``` In Index.php line 42: Doctrine\DBAL\Schema\Index::__construct(): Argument #1 ($name) must be of type ?string, int given, called in vendor/doctrine/orm/src/Tools/SchemaTool.php on line 340 ``` #### Expected behavior <!-- What was the expected (correct) behavior? --> The unique constraint should be loaded correctly and a unique name should be generated for it automatically.
admin added the pull-request label 2026-01-22 16:15:38 +01:00
admin closed this issue 2026-01-22 16:15:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#12934