Changes between Version 53 and Version 54 of NewbieMistakes


Ignore:
Timestamp:
05/20/13 17:53:06 (23 months ago)
Author:
berkerpeksag
Comment:

Code highlight.

Legend:

Unmodified
Added
Removed
Modified
  • NewbieMistakes

    v53 v54  
    7979==== Problem ====
    8080
    81 When you have a Field: current_zip = meta.IntegerField(maxlength=5,blank=True)
    82 
    83 django will create a not nullable field in the DB.  However leaving the field blank (in admin/web) django will try and insert a NULL value in the DB.
    84 
    85 ==== Solution ====
    86 
    87 Add null=True:
    88 
    89 current_zip = meta.IntegerField(maxlength=5,null=True,blank=True)
     81When you have a Field:
     82
     83{{{
     84#!python
     85current_zip = meta.IntegerField(maxlength=5, blank=True)
     86}}}
     87
     88Django will create a not nullable field in the database.  However leaving the field blank (in admin or web interface) Django will try and insert a {{{NULL}}} value in the database.
     89
     90==== Solution ====
     91
     92Add {{{null=True}}}:
     93
     94{{{
     95#!python
     96current_zip = meta.IntegerField(maxlength=5, null=True, blank=True)
     97}}}
    9098
    9199== Date & NULLS ==
     
    390398Prepend "lambda:" like
    391399{{{
     400#!python
    392401MyRandNum = models.CharField(max_length=4, default=lambda:random.randint(1000,9999))
    393402}}}
Back to Top