from django.core.management.base import BaseCommand from django.db import connection class Command(BaseCommand): help = ( "Rebuild the SQLite FTS5 search index from scratch. No-op on Postgres, " "which computes its search vector at query time instead of maintaining " "a separate index." ) def handle(self, *args, **options): if connection.vendor != "sqlite": self.stdout.write("Not using SQLite — nothing to rebuild.") return with connection.cursor() as cursor: cursor.execute("INSERT INTO articles_fts(articles_fts) VALUES ('rebuild')") self.stdout.write(self.style.SUCCESS("Rebuilt the SQLite FTS5 search index."))