Define a default operator class for DateTimeRangeField index

Hi
I build this model which has two DateTimeRange fields:

class Booking(BaseModel):

class Status(models.TextChoices):
    PAID = "Paid", _("Paid")
    EXPIRED = "Expired", _("Expired")
    PEDNING = "Pending", _("Pending")
    ACCEPTED = "Accepted", _("Accepted")
    REJECTED = "Rejected", _("Rejected")
    CANCELLED = "Cancelled", _("Cancelled")

related_property = models.ForeignKey(
    to='Property.Property', on_delete=models.PROTECT, null=False,
    verbose_name=_("Property"), related_name="bookings", related_query_name="booking"
    )
client = models.ForeignKey(
    to='Authentication.Client', on_delete=models.PROTECT, null=False,
    verbose_name=_("User"), related_name="reservations", related_query_name="reservation"
)
client_checking_range = DateTimeRangeField(
    default_bounds='[]', verbose_name=_("Reservation"), null=True) # to be false
original_reservation = DateTimeRangeField(
    default_bounds='[]', verbose_name=_('Original Reservation'), null=True) # to be false
checked_in = models.BooleanField(default=False, null=False, verbose_name=_('Checked In'))
checked_out = models.BooleanField(default=False, null=False, verbose_name=_('Checked Out'))
price = models.PositiveIntegerField(verbose_name=_("Price"), null=False, default=1) # default to be removed
num_of_adults = models.SmallIntegerField(null=False, verbose_name=_("Num of adults"))
num_of_children = models.SmallIntegerField(null=False, verbose_name=_("Num of children"))
status = models.CharField(verbose_name=_("Status"), max_length=16,
    choices=Status.choices, default=Status.PEDNING, null=False)

class Meta:
    verbose_name = _("Booking")
    verbose_name_plural = _("Bookings")

    indexes = [
        # models.Index(fields=['client_checking_range',]),
        GinIndex(
            fields=['client_checking_range', ],
            name='booking_client_range_gin_idx'
        )
        # GistIndex(
        #     fields=('client_checking_range',),
        #     name='checking_range_gist_idx',
        #     buffering=True
        #     ),
        # GistIndex(
        #     OpClass('client_checking_range', name='range_ops'),
        #     # fields=('client_checking_range', ),
        #     name='client_checking_range_gist_idx',
        #     # opclasses=['range_ops'],
        #     buffering=True
        #     ),
        # GistIndex(
        #     fields=('original_reservation', ),
        #     name='original_reservation_gist_idx',
        #     opclasses=['range_ops'],
        #     buffering=True
        #     )
    ]

    constraints = [
        ExclusionConstraint(
            name="non_overlapped_reservation",
            expressions=[
                # ("client_checking_range", RangeOperators.OVERLAPS),
                (OpClass("client_checking_range", name="range_ops"), RangeOperators.OVERLAPS),
                ("related_property", RangeOperators.EQUAL)
            ],
            condition=Q(status="Accepted") | Q(status="Paid") | Q(status="Pending"),
        )
    ]

I built the rest api for this model and do some tests on postman, then I try to build unittest for this APIs, and when I call pytest from the terminal, it always show this error message:
E django.db.utils.ProgrammingError: data type bigint has no default operator class for access method “gist”
E HINT: You must specify an operator class for the index or define a default operator class for the data type.

as you can see in the model I try multiple indexing solutions (and others tried but not showed here) but the result still same, so any one can help me with this problem?

thanks very much

Ran into this as well and solved it by installing the btree_gist extension.

Django offers convenient installation of this through the BtreeGistExtension migration operation. This allows the database to create indexes for data types and operations that are not supported by standard B-tree indexes.

Steps:

  1. Create an empty migration: ./manage.py makemigrations myapp --empty
  2. Add the operation to the migration file:
    from django.db import migrations
    from django.contrib.postgres.operations import BtreeGistExtension
    
    class Migration(migrations.Migration):
    
      dependencies = [
      ]
    
      operations = [
          BtreeGistExtension(), # Add this.
      ]
    
  3. Migrate. ./manage.py migrate

Ensure this migration is applied before any other migrations that depend on the btree_gist extension.