0

in models.py, I set ComissionRate field IntegerField blank=True, but in actual, this ComissionRate field also must be not null

class System(models.Model):         
    BulletinBoardContent = models.CharField(max_length=64,blank=True)   
    BulletinBoardDescription = models.TextField(blank=True)  
    BulletinBoardDate = models.DateField(blank=True)  
    ComissionRate = models.FloatField(blank=True)

when I insert a new system item, if I don't fill ComissionRate, there will have an error as follows:
Exception Type: IntegrityError
Exception Value: system_system.ComissionRate may not be NULL

PS:DateField has the same situations.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
Kathy
  • 1
  • 1
  • possible duplicate of [differentiate null=True, blank=True in django](http://stackoverflow.com/questions/8609192/differentiate-null-true-blank-true-in-django) – Louis Oct 13 '14 at 10:45
  • Thank you. But I had tried. It is still not work. – Kathy Oct 15 '14 at 11:16

2 Answers2

3

Yes. That is clearly documented:

Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, form validation will allow entry of an empty value. If a field has blank=False, the field will be required.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

Two most common options for a blank field in your model are:

  • (blank=True) if the field is CharField or TextField (or any other string fields)
  • (blank=True, null=True) for other fields: FloatField, IntegerField, DateField etc.

Databases can accept a blank (empty) string, but there's no "blank date" or "blank integer". You must use a special SQL NULL marker indicating that a non-string field is blank.