doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.94k stars 2.52k forks source link

Unique constraint definition #11711

Open klosto opened 1 week ago

klosto commented 1 week ago

Bug Report

Error in unique constraint definition

Q A
Version 2.13.0

Summary

When I tried to define unique constraint in ORM\Table() annotation, it didn't even created any setting in migration. Then I tried to define it in separated annotation like #[ORM\UniqueConstraint] and it worked.

#[ORM\Table(
    name: 'address',
    uniqueConstraints: [
        new ORM\UniqueConstraint(name: 'UNIQUE_id_public', fields: ['id_public']),              // Doesn't work
        new ORM\UniqueConstraint(name: 'UNIQUE_primary', fields: ['id', 'primary'])
    ]
)]
#[ORM\UniqueConstraint(name:'UNIQUE_id_public', fields: ['publicId'])]                          // Works

Am I doing something wrong, or is it expected behavior?