Django south migration - Adding FULLTEXT indexes

前端 未结 2 2114
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 13:59

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 manuall

2条回答
  •  忘掉有多难
    2021-02-12 14:27

    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:

    from django.db import migrations
    
    class Migration(migrations.Migration):
    
        operations = [
            migrations.RunSQL(
                sql="CREATE FULLTEXT INDEX `index_name` on table_name(`column_name`);",
                reverse_sql="ALTER TABLE table_name DROP INDEX index_name"
            )
        ]
    

提交回复
热议问题