2

So, im trying to work on my apps and I have PositiveBigIntegerField's in some of my models. I thought for sure it was already included with Django but now i'm starting to think otherwise. Whenever I run my server, im getting an error stating that AttributeError: module 'django.db.models' has no attribute 'PositiveBigIntegerField' Has anyone run into this problem before?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Alec
  • 27
  • 8

1 Answers1

2

So, I'm trying to work on my apps and I have PositiveBigIntegerField's in some of my models. I thought for sure it was already included with Django but now I'm starting to think otherwise.

It is, but only since . Indeed, the documentation of the PostiveBigIntegerField [Django-doc] specifies that this was introduced then.

You can however easily implement this yourself, as specified in the source code [GitHub]:

class PositiveBigIntegerField(PositiveIntegerRelDbTypeMixin, BigIntegerField):
    description = _("Positive big integer")

    def get_internal_type(self):
        return "PositiveBigIntegerField"

    def formfield(self, **kwargs):
        return super().formfield(
            **{
                "min_value": 0,
                **kwargs,
            }
        )

Where you thus import PositiveIntegerRelDbTypeMixin and BigIntegerField from the django.db.models.fields module.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555