Django Database Validations
I ran into some weird behavior today with the Django ORM and its version of data validations. I am still having a little trouble understanding what it considers blank in terms of a charfield.
So by default, the Django ORM has a lot of things set to false, including blank, and null. That seems logical.
So theoretically this should not allow me to create and save an object that has a blank feild
name = models.CharField(max_length=500)
But it does.
$ m = Meetup()
$ m.save()
This totally save instead of throwing an error.
I eventually found out that CharFields get set to an empty string by default. So if you set default to false, you are back in business.
name = models.CharField(max_length=500, default=False)
Now we get an IntegrityError, which is awesome. That keeps us from passing in blank things from form fields. But if we jump into the shell and pass a blank string, still no error. Is this just a limitation of the Django ORM?Still searching for the answer.