Postgres queries are CaSeSensitivE unlike in MySQL. So when a simple Model.objects.get(field='hello')
would get the record. In postgres you would need to use field__iexact='hello'
In fact,unique
doesn't work was different cases with standard postgres. That is why django has the CIText Mixin and postgres has the citext
extension
Unfortunately this won't help for a unique_together
field. The case sensitivity will still come into play.
So you can make the field lowercase by overriding the model's save method:
def save(self, **kwargs):
'''Override save to enforce project name is lowercase'''
self.name = self.name.lower()
super().save()
Nope you don't need to do the above. Just ensure the field is a CICharField
Ran into another problem:
crowdminder=# create extension citext;
ERROR: extension "citext" already exists
So citext
is already there but when running a django migration I get:
django.db.utils.ProgrammingError: type "citext" does not exist
LINE 1: ...llink" ("id" serial NOT NULL PRIMARY KEY, "email" citext NUL...
FFFFFFFFFFFuck you postgres
This is flippen weird.
So I go into psql
and raise hell:
drop extension citext cascade;
Then the migrate works. It's crazy. If this shit happens on production, I will be pissed at pg
.