I have an unusual index, which is consists of:
some_field
, COALESCE(other_field, 0)
So I’m trying to use it in description of my entity
#[ORMUniqueConstraint(
name: 'some_index',
columns: ['some_field', 'COALESCE(other_field, 0)']
)]
Of course, doctrine cannot find such column and returns error, while running command php bin/console make:migration
or php bin/console doctrine:migrations:diff
:
There is no column with name "COALESCE(other_field, 0)" on table "..."
Is there any possible way to continue using commands from maker-bundle
or doctine-bundle
to generate new migrations without such kind of errors?
2
Answers
If somebody is interested in the idea of removing such kind of errors when executing command, I realized to add virtual property for doctrine's entity:
Now it's generating extra fields(sql queries), but without any errors.
Unfortunately, Doctrine doesn’t support complex SQL functions like COALESCE() directly in its schema management (e.g., when generating migrations or entity mapping), so it treats COALESCE(other_field, 0) as if it were a column name, hence the error.
You can Manually Manage Custom Indexes in Migrations or else have to Ignore the Index in Doctrine Schema using