Saturday, August 26, 2017

Is some problem in field options 'null'?

I read the document about field options 'null'.

It is said that.

If True, Django will store empty values as NULL in the database. Default is False.

Avoid using null on string-based fields such as CharField and TextField. If a string-based field has null=True, that means it has two possible values for "no data": NULL, and the empty string.


Then I try make a field have "null=True", just save it to database.

like that.

>>> from backend.models import Scrapyd as S
>>> s = S()
>>> s.comment
>>> type(s.comment)
<class 'NoneType'>
>>> s.save()
>>> b  = S.objects.all().last()
>>> b
<Scrapyd: Scrapyd object>
>>> b.comment
>>> type(b.comment)
<class 'NoneType'>


What my question is why the value not like the document said is empty string ''?

I am confused.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1b239340-78d6-4df2-a12d-9531dfe7912d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment