Hey,
I have a model which has a date and a foreign key field. I want a uniqueness constraint that each fk can only be used once per month, so Unique(date__year, date__month, fk). However, when I use this in my model’s metadata:
models.UniqueConstraint(fields=['date__year', 'date__month', 'category'], name='date_month_cat_unique')
I get an error that the date__year field doesn’t exist. This is a bit strange because I use this syntax throughout my app and I also know that such constraints are supported by Postgres:
create unique index year_month_uq
on foo
( extract(year from mydate),
extract(month from mydate)
) ;
What am I doing wrong here? I’m using Django 3 and Postgres.
Thanks