til: django_migration-postgresql-fuzzystrmatch.md
- path
-
django_migration-postgresql-fuzzystrmatch.md
- topic
-
django
- title
-
Enabling the fuzzystrmatch extension in PostgreSQL with a Django migration
- body
-
The PostgreSQL [fuzzystrmatch extension](https://www.postgresql.org/docs/13/fuzzystrmatch.html) enables several functions for fuzzy string matching: `soundex()`, `difference()`, `levenshtein()`, `levenshtein_less_equal()`, `metaphone()`, `dmetaphone()` and `dmetaphone_alt()`. Enabling them for use with Django turns out to be really easy - it just takes a migration that looks something like this: ```python from django.contrib.postgres.operations import CreateExtension from django.db import migrations class Migration(migrations.Migration): dependencies = [ ("core", "0089_importrun_sourcelocation"), ] operations = [ CreateExtension(name="fuzzystrmatch"), ] ```
- html
-
<p>The PostgreSQL <a href="https://www.postgresql.org/docs/13/fuzzystrmatch.html" rel="nofollow">fuzzystrmatch extension</a> enables several functions for fuzzy string matching: <code>soundex()</code>, <code>difference()</code>, <code>levenshtein()</code>, <code>levenshtein_less_equal()</code>, <code>metaphone()</code>, <code>dmetaphone()</code> and <code>dmetaphone_alt()</code>.</p> <p>Enabling them for use with Django turns out to be really easy - it just takes a migration that looks something like this:</p> <div class="highlight highlight-source-python"><pre><span class="pl-k">from</span> <span class="pl-s1">django</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">postgres</span>.<span class="pl-s1">operations</span> <span class="pl-k">import</span> <span class="pl-v">CreateExtension</span> <span class="pl-k">from</span> <span class="pl-s1">django</span>.<span class="pl-s1">db</span> <span class="pl-k">import</span> <span class="pl-s1">migrations</span> <span class="pl-k">class</span> <span class="pl-v">Migration</span>(<span class="pl-s1">migrations</span>.<span class="pl-v">Migration</span>): <span class="pl-s1">dependencies</span> <span class="pl-c1">=</span> [ (<span class="pl-s">"core"</span>, <span class="pl-s">"0089_importrun_sourcelocation"</span>), ] <span class="pl-s1">operations</span> <span class="pl-c1">=</span> [ <span class="pl-v">CreateExtension</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">"fuzzystrmatch"</span>), ]</pre></div>
- created
-
2021-04-18T12:32:58-07:00
-
created_
utc -
2021-04-18T19:32:58+00:00
- updated
-
2021-04-18T12:32:58-07:00
-
updated_
utc -
2021-04-18T19:32:58+00:00
-
shot_
hash -
a95d79750b014c729ca6aca5db4665ee
- slug
-
migration-postgresql-fuzzystrmatch