You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When blank=True is specified at a Djang Field, ModelSchema treats the field as nullable even if null=False is also specified there. So, ModelSchema passes null to the Django model and it raise NOT NULL constraint exception.
class CharFieldVerification(models.Model):
char_field = models.CharField(max_length=200, blank=True, null=False)
class TextFieldVerification(models.Model):
text_field = models.TextField(blank=True, null=False)
class DateFieldVerification(models.Model):
date_field = models.DateField(blank=True, null=False)
class FileFieldVerification(models.Model):
file_field = models.FileField(blank=True, null=False)
class BooleanFieldVerification(models.Model):
boolean_field = models.BooleanField(blank=True, null=False)
The combination of blank=True and null=False seems to be common in string-based Django fields, which is mentioned in Django Model field reference
The text was updated successfully, but these errors were encountered:
tomatod
changed the title
Some function to exclude Django Field blank option from nullable determination
Option to exclude Django Field blank option from nullable determination
Apr 13, 2025
tomatod
changed the title
Option to exclude Django Field blank option from nullable determination
Option to exclude Django Field blank option from determination of 'nullable'
Apr 13, 2025
According to the Django reference, the blank option is mainly for form validation. Django is originally made for form applications and the target content-type is application/x-www-form-urlencoded, so I think Django field has the blank option because the content-type cannot express null explicitly.
Json can express null originally, so I think as an option it would be good if ModelSchema could simply look only at the null option.
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
When blank=True is specified at a Djang Field, ModelSchema treats the field as nullable even if null=False is also specified there. So, ModelSchema passes null to the Django model and it raise NOT NULL constraint exception.
The combination of blank=True and null=False seems to be common in string-based Django fields, which is mentioned in Django Model field reference
Other related Issue
The text was updated successfully, but these errors were encountered: