On Thu, 2021-04-08 at 16:36 -0500, Ryan Nowakowski wrote: > On Wed, Apr 07, 2021 at 03:25:53PM +0100, Roger Gammans wrote: > > This is mostly (form the Django perspective) and issue with > > CharFields, > > because a CharField can store None or ''. For values of '' > > in CharField, IIRC, django will convert them to null, with > > null=True, > > blank=True. But not with blank=True,null=False.See also : > > https://docs.djangoproject.com/en/3.1/ref/models/fields/#null > > I read the documentation a bit differently. My interpretation is > that > CharField(null=True) means that both ''(empty string) and None(null) > are > valid values. But no implicit conversion from '' to None takes > place. > > CharField(null=False) means that None(null) isn't a valid value and > that > only ''(empty string) is permitted.
I understand that reading, and the simple answer is we are both right! See: https://github.com/django/django/blob/45a58c31e64dbfdecab1178b1d00a3803a90ea2d/django/db/models/fields/__init__.py#L1082 This shows the model field telling the any auto creating form field, say like in the admin model, which value to prefer 'empty' values. Since it's not the model field, so any python code which saves '' and None, directed onto the model will still have those respected as '' and NULL. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2d0608b7d8c120af35d98c194659de1f89fafd08.camel%40gammascience.co.uk.