Would recent commit solve the problem for you: https://github.com/django/django/commit/267dc4adddd2882182f71a7f285a06b1d4b15af0
Relevant ticket: https://code.djangoproject.com/ticket/4136 On Fri, Jun 17, 2016 at 3:27 AM, Luke Benstead <[email protected]> wrote: > Hi! > > We've recently hit upon a problem where we need empty strings in a > CharField to be coerced to NULL. Obviously nullable CharField's are frowned > upon but we have the requirement that non-empty values must be unique, so > the empty state must be NULL. > > We've written a custom subclass of CharField to deal with this, but when I > found the bug report[1] for this issue, the wontfix justification was that > it would make things backwards incompatible. What I'm proposing instead is > we add another option to CharField's __init__ which defaults to true called > "allow_empty_strings". If set to False, and the field is nullable, this > would coerce empty values to None. If the field was not nullable, this > would raise an exception (ValueError?, IntegrityError?). > > Is this an acceptable solution to support this use-case? > > Thanks, > > Luke. > > [1] https://code.djangoproject.com/ticket/9590 > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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/ad3d155c-6386-4d4f-a4f3-07544c2f127e%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/ad3d155c-6386-4d4f-a4f3-07544c2f127e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. 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/CADhq2b5cU_Ce6g_9k%2BHeCfgNSFbOV3YFtpAffoAsHsEhwNwi5A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
