I have a model with a Charfield:
class SomeModel(models.Model):
charfield = models.Charfield(max_length=5, default="")
...
I expect this field to be not required when using in the admin. But when I include this model to the admin, I have this field required. I could use null=True, blank=True, but I'm curious Is it some kind of a bug or am I implementing something wrong?
I'm not sure why you think that's a bug. If you don't specify blank=True, some kind of non-empty value is required. The empty string, by definition, is an empty value; so Django quite correctly displays an error telling you to supply an actual value.
You do need to specify blank=True if you want the empty string to be allowed. But you don't need to specify null=True; indeed, as the docs show, you shouldn't use that on CharFields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With