Django models `EmailField` default is empty string - Not `None` (or Null) . Why ?

806 views
Skip to first unread message

Carlos Leite

unread,
Jun 13, 2021, 7:18:09 AM6/13/21
to django-d...@googlegroups.com

Yesterday I realized that, Django email field default value is not "Null" actually is an empty string ("")  - Although I'm not code often, I was surprised.

I wrote some tests for a model where an  `emailfield` was supposed to be `null=False`.

But during the tests, it didn't raise an Exception (when persist on DB). Or for a ModelForm `is_valid` in fact was True.

I did some (not a lot) research, and it seems the default value for an empty value for EmailField is ""
Isn't it counter productive? (at least for me, it was)
I believe, the empty value,  is a special case for a Model Field
and I couldn't find any  information on docs. (I told I did SOME research)
Please let me know my expectations make sense, I'll do my best for help,
if not, I know its not the place for "help", just tell me I'm wrong.

Thanks everyone.

--------------------------------------------------------------------
Cadu Leite
| Twitter    
| @cadu_leite

Aymeric Augustin

unread,
Jun 14, 2021, 2:53:22 AM6/14/21
to django-d...@googlegroups.com
--
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-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAEM6-Q%2B1VHddFaXWNFgdd3fU%2B1BHOVo0U%3De-SOt2-ptFq24CcQ%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages