PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Wie entferne ich den Index varchar_pattern_ops bei einer Django (1.8)-Migration?

Ok, ich habe hier ein paar Informationen gefunden https://docs.djangoproject.com/en/1.8/_modules/django/db/backends/base/schema/#BaseDatabaseSchemaEditor.alter_field

Und erstellte ein manuelles RunPython Migration zum Löschen der varchar_pattern_ops Index mit dem SchemaEditor

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


import re
def drop_md5hash_varchar_pattern_ops_index(apps, schemaEditor):
    # code based on https://docs.djangoproject.com/en/1.8/_modules/django/db/backends/base/schema/#BaseDatabaseSchemaEditor.alter_field
    model = apps.get_model("logger", "Btilog")
    index_names = schemaEditor._constraint_names(model, index=True)
    for index_name in index_names:
        if re.search('logger_btilog_md5hash_.+_like', index_name):
            print 'dropping index {}'.format(index_name)
            schemaEditor.execute(schemaEditor._delete_constraint_sql(schemaEditor.sql_delete_index, model, index_name))


class Migration(migrations.Migration):
    dependencies = [
        ('logger', '0012_auto_20150529_1745'),
    ]

    operations = [
        # Remove the annoying index using a hack
        migrations.RunPython(
            drop_md5hash_varchar_pattern_ops_index
        ),
    ]