Thursday, 12 September 2013

When variables not allowed to be null are actually created with no data on Django

When variables not allowed to be null are actually created with no data on
Django

I was recently adding large amounts of data from a JSON file to my Django
"member" model. For this purpose I had to make most of my variables able
to take in null or blank in order to handle cases when the JSON file did
not have information on a specific variable etc etc.
event = models.CharField(max_length=200, blank=True, null=True)
tool = models.CharField(max_length=200, blank=True, null=True)
other = models.CharField(max_length=200)
protocol = models.CharField(max_length=200)
However, I accidentally forgot to change 2 variables for this purpose.
Surprisingly my objects were generated without a problem even when the
JSON data was not adding anything to this variables.
So here is my question(s):
How was the member object created when some variables that are not allowed
to be null, were actually null or at the very least had no data.
I thought this restriction was at the Database level but it seems here
like it is only for user submitted data since when I created the object
internally it actually allowed me to have several null/blank variables.
Is Django taking care of something behind the scenes for me?
I know this is a lot but I hope it makes sense.... thanks

No comments:

Post a Comment