Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0 value in Django PositiveIntegerField?

Can a field of type models.PositiveIntegerField contain a 0 value? I'm doing something like:

points = models.PositiveIntegerField(default=0) 

Thanks,

I know I should try ir myself, but I haven't a Django environment here.

like image 632
Juanjo Conti Avatar asked Feb 11 '10 23:02

Juanjo Conti


People also ask

What is PositiveIntegerField Django?

PositiveIntegerField is a integer number represented in Python by a int instance. This field is like a IntegerField but must be either positive or zero (0). The default form widget for this field is a NumberInput when localize is False or TextInput otherwise.

What is null False in Django?

null. If True , Django will store empty values as NULL in the database. Default is False .

Can an integer field be null in Django?

For example, adding an argument null = True to IntegerField will enable it to store empty values for that table in relational database. Here are the field options and attributes that an IntegerField can use. If True, Django will store empty values as NULL in the database.

What is Auto_created in Django?

@Raphael In a migration, an auto_created model gets created by the AddField operation for the ManyToManyField -- it does not exist as a separate model, only as part of the model that defines the m2m field.


2 Answers

Yes, it can. It is debatable whether it should--there is a longstanding bug report: http://code.djangoproject.com/ticket/7609

like image 124
Michael Greene Avatar answered Oct 03 '22 05:10

Michael Greene


Yes.

The model field reference says so. For completeness, also quoted here:

PositiveIntegerField

class PositiveIntegerField([**options]) 

Like an IntegerField, but must be either positive or zero (0). The value 0 is accepted for backward compatibility reasons.

like image 31
jontsai Avatar answered Oct 03 '22 05:10

jontsai