I have a postgres Database and a model with a field as blank=False and null=True. Let's say:
class MyModel(models.Model):
param1 = models.CharField(max_length=1024)
param2 = models.CharField(max_length=1024)
info = models.CharField(max_length=1024, blank=False, null=False)
Now, when I am creating a model like this:
m = MyModel(param1=val1, param2=val2)
it basically won't raise any exception for info
field on saving. Even more, it will keep an empty value for info
in the database after using save
method.
UPDATED
When instantiating the model like this:
m = MyModel(param1=val1, param2=val2, info=None)
saving will raise an exception in that case
Any suggestions why does it happen? In my opinion if I miss to add a value in the model initialization, it should be at least assumed as None
, but it's not. I googled that and couldn't find an specific answer for that. But, found that only full_clean()
model method performs checking and raises exceptions like these:
ValidationError: {'info': ['This field cannot be blank.'], 'owner': ['This field cannot be blank.']}
Any help is welcome!