Home > database >  Django PositiveBigIntegerField
Django PositiveBigIntegerField

Time:07-19

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?

CodePudding user response:

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.

  • Related