django-postgres-copy icon indicating copy to clipboard operation
django-postgres-copy copied to clipboard

Drop indexes doesn't drop indexes created using Meta.indexes

Open mikicz opened this issue 3 years ago • 2 comments

Since Django 1.11 (current version 3.0), there's a new way of adding indexes to django tables, Meta.indexes (https://docs.djangoproject.com/en/3.0/ref/models/options/#django.db.models.Options.indexes). This package doesn't work with these, it only works with db_index on fields themselves and the Meta.index_together option (which currently has a warning in the docs that Meta.indexes should be used instead).

mikicz avatar Jul 10 '20 07:07 mikicz

Can you show me an example that would recreate this bug?

palewire avatar Dec 11 '21 12:12 palewire

So imagine you have this table:

from django.db import models
from postgres_copy import CopyManager

class Customer(models.Model):
    first_name = models.CharField(max_length=100, db_index=True)
    last_name = models.CharField(max_length=100, db_index=True)

    objects = CopyManager()

    class Meta:
        indexes = [
            models.Index(fields=['last_name', 'first_name']),
        ]

The indexes regularly look like this (for the two fields there's two indexes, one is for exact and one for %like% (I believe, doesn't really matter I guess). image

If you run Customer.objects.drop_indexes() then the first_name/last_name indexes get dropped and the joined one remains: image

mikicz avatar Dec 15 '21 17:12 mikicz