I need to add a FULLTEXT index to one of my Django model's fields and understand that there is no built in functionality to do this and that such an index must be added manually in mysql (our back end DB).
I want this index to be created in every environment. I understand model changes can be dealt with Django south migrations, but is there a way I could add such a FULLTEXT index as part of a migration?
In general, if there is any custom SQL that needs to be run, how can I make it a part of a migration.
Thanks.
In newer versions of Django, you can create an empty migration for execute custom sql:
python3 manage.py makemigrations --empty app_name
Then, in the generated migration:
You can write anything as a migration. That's the point!
Once you have
South
up and running, type inpython manage.py schemamigration myapp --empty my_custom_migration
to create a blank migration that you can customize.Open up the
XXXX_my_custom_migration.py
file inmyapp/migrations/
and type in your custom SQL migration there in theforwards
method. For example you could usedb.execute
The migration might look something like this: