Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mikicz opened this issue Jul 10, 2020 · 2 comments
Open

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

mikicz opened this issue Jul 10, 2020 · 2 comments
Labels

Comments

@mikicz
Copy link

mikicz commented Jul 10, 2020

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).

@palewire
Copy link
Owner

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

@palewire palewire added the bug label Dec 11, 2021
@mikicz
Copy link
Author

mikicz commented Dec 15, 2021

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

geoffrey-eisenbarth added a commit to geoffrey-eisenbarth/django-postgres-copy that referenced this issue Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants