Answer from @SaeX in another thread:
How can I activate the unaccent extension on an already existing model
A migration file needs to be manually made and applied.
- First, create an empty migration:
./manage.py makemigrations myapp --empty
- Then open the file and add UnaccentExtension to operations:
from django.contrib.postgres.operations import UnaccentExtension
class Migration(migrations.Migration):
dependencies = [
(<snip>)
]
operations = [
UnaccentExtension()
]
- Now apply the migration using
./manage.py migrate.
If you'd get following error during that last step:
django.db.utils.ProgrammingError: permission denied to create extension "unaccent"
HINT: Must be superuser to create this extension.
... then temporarily allow superuser rights to your user by performing postgres# ALTER ROLE <user_name> SUPERUSER; and its NOSUPERUSER counterpart. pgAdminIII can do this, too.
Now enjoy the unaccent functionality using Django:
>>> Person.objects.filter(first_name__unaccent=u"Helène")
[<Person: Michels Hélène>]
Again, this answer belongs to @SaeX
But for me his answer still didn't work, so don't forget to
add the line django.contrib.postgres
in INSTALLED_APPS (settings.py)