Hello Daniel,

thanks for you reply

2011/2/10 Daniel Roseman <dan...@roseman.org.uk>:
>> >>> from test_django.roman.models import Jtem
>> >>> o=Jtem.objects.get(pk=29)
>> >>> o.name=''
>> >>> o.save()
>>
>> Now the record looks like this:
>>
>> mysql> select * from roman_jtem where id=29;
>> +----+------+----------+
>> | id | name | nachname |
>> +----+------+----------+
>> | 29 |      | Klesel   |
>> +----+------+----------+
>> 1 row in set (0.00 sec)
>>
>> This is not what I expected! The empty string should have been
>> converted into a null value!
>
> Why? What makes you think that? There is nothing that implies that should
> happen.

The setting (blank=True, null=True) make me think like that.

> You explicitly set the field to an empty string,

Yes,  which evaluates to an equivalent of None or False in python, and
with the above setting I've declared that None values should be
allowed and should be stored as NULL in the database.

> so I can't think of
> any reason why it should somehow be converted to a null.

I've mentioned the reason a bit further down in my first post:

When I start to edit the records of this table with the django
application, gradually all NULL Values will be converted into empty
string values. Because the form always posts an empty string as
None/NULL value. And if I don't take further care of converting them
back. that's just what happens. However I thought with
name=models.CharField(blank=True, null=True)
that django should convert None values to NULL.

Oh, ... no ... I just reread the docs ...
"""
 Avoid using null on string-based fields such as CharField and
TextField unless you have an
 excellent reason. If a string-based field has null=True, that means
it has two possible values
 for “no data”: NULL, and the empty string. In most cases, it’s
redundant to have two possible
 values for “no data;” Django convention is to use the empty string, not NULL.
"""

You are right... that's how it's meant to be ...

> Rather than patch Django, you could subclass CharField to do the conversion,

Yes of course. If the behavior as is, is what is wanted, that's my way
to go. I'm just wondering if this is really so... but it looks like
it...

Regards Roman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to