1

I have implemented full text search in my django app using postgresql. But, when I press the search button, I get an error:

ProgrammingError at /blog/search/
function similarity(character varying, unknown) does not exist
LINE 1: SELECT COUNT(*) FROM (SELECT SIMILARITY("blog_post"."title",...
                                     ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

I don't know where the error is, so if you need any files, I will edit this question. Please help me

Samyak Jain
  • 347
  • 1
  • 4
  • 17

2 Answers2

3

I'm guessing you forgot to install the pg_trgm extension. To install it using django, create a file called pg_trgm.py inside of your app's migrations directory:

from django.db import migrations

class Migration(migrations.Migration):
    dependencies = [
        ('myapp', <last migration filename here>),
    ]
    operations = [
        migrations.RunSQL('CREATE EXTENSION IF NOT EXISTS pg_trgm'),
    ]

Remember to replace <last migration filename here> with the filename of your most recent migration.

Lord Elrond
  • 13,430
  • 7
  • 40
  • 80
  • This works perfectly. but could you tell me a solution that is permanant. I have to repeat this step in every django project, which I don't want to. Thanks for your help – Samyak Jain Dec 01 '20 at 11:01
0

Are you working with 'Django by Example' book? Did you put the real DB at 'psql blog' command ? I get the same error, so I tryed 'psql blogDB'... the real name that I gave. That work fine!