How to create a full text index on an existing model?

We have an existing Django v3.1 project using MariaDB v10.5, and the database supports full text index according to the official website.

About how to search the text column with a full text index, we found this example on MySQL, and we suppose MariaDB works similarly.

Our Question:

  • We could not find any example of migration creating a full text index. So, we wonder how to do it.

  • After building the full text index, searching uses SQL like SELECT * FROM table WHERE MATCH(text_column) AGAINST('pattern' in natural language mode);. So, we wonder how to do it with Django.

Django only supports full text search for postgres. If you’re stuck using MariaDB, you can write a migration with the RunSQL operation to define the indexes and use the raw manager method to write your full text search queries.

1 Like