@@ -0,0 +1,628 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import unicode_literals%0A%0Afrom django.db import migrations, models%0A%0AINDEX_SQL = %22%22%22%0A DO $$%0A BEGIN%0A%0A IF NOT EXISTS (%0A     SELECT 1 FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace%0A     WHERE c.relname = 'msgs_msg_responded_to_not_null' AND n.nspname = 'public') THEN%0A     CREATE INDEX msgs_msg_responded_to_not_null ON msgs_msg (response_to_id) WHERE response_to_id IS NOT NULL;%0A END IF;%0A%0A END$$;%22%22%22%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('msgs', '0047_auto_20160307_1919'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunSQL(INDEX_SQL),%0A    %5D%0A

Use partial index for responded_to_id