Symfony Doctrine UniqueConstraint error Constant expression contains invalid operations

Viewed 54

Attempting to create a UniqueConstraint for two fields with Doctrine on a Postgres db, I am getting the error when running make:migration.

"Compile Error: Constant expression contains invalid operations"

I searched around on SO and it seems to be related to creating a static property in a class.

Not sure why it is interpreting the code below that way:

 #[
ORM\Entity(repositoryClass: SalesChannelRepository::class),
ORM\Table(
    name: "sales_channel",
    schema: "my_schema",
    UniqueConstraint: [
        UniqueConstraint(
            name: "name_idx",
            fields: ["sales_channel_name_id", "multi_channel_id"]
        ),
    ]
),
]

The attributes seem in line with Doctrine documentation.

I did try a few variants, like using columns instead of fields, or using ORM\UniqueConstraint, but that did not help.

Running make:migration after removing that specific attibute works fine.

1 Answers
Related