PostgreSQL
 sql >> Base de données >  >> RDS >> PostgreSQL

Comment supprimer l'index varchar_pattern_ops dans une migration django (1.8) ?

Ok, j'ai trouvé des infos ici https://docs.djangoproject.com/en/1.8/_modules/django/db/backends/base/schema/#BaseDatabaseSchemaEditor.alter_field

Et fait un RunPython manuel migration pour supprimer le varchar_pattern_ops indexer à l'aide de 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
        ),
    ]