While it is probably not possible to change how Django treats this, many newcomers find it super confusing. To make developer experience in our Oracle-based project better, we started using the following workaround for fields which are required to be not null and not empty string:
class NonEmptyCharField(models.CharField): """ CharField preventing empty string and null It workarounds two problems: - CharField has a default value '' which allows silent save of model without an error even if we forget to set mandatory fields. This is solved by setting the default to None causing db error on not null constraint. - The above is not sufficient for Oracle as the db backend has hardcoded null=True regardless of what we set. This is changed by empty_strings_allowed=False. """ empty_strings_allowed = False def __init__(self, *args, **kwargs): kwargs.setdefault('default', None) super().__init__(*args, **kwargs) Dne čtvrtek 8. listopadu 2018 13:43:25 UTC+1 Florian Apolloner napsal(a): > > Oracle treats NULL and empty varchar2 the same; so null=True/False is > simply not possible on Oracle for CharField. I am not sure what you are > proposing here… > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/831649d2-80d2-410d-ac4d-9304010eb6a0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.