On Thursday, February 10, 2011 10:19:49 AM UTC, Roman Klesel wrote: > > Hello community, > > I'm using a django version 1.3 beta 1 SVN-15481 and a mysql 5 backend > > I have the following field definition in my model: > > class Jtem(models.Model): > name=models.CharField(blank=True, null=True, max_length=255) > nachname=models.CharField(max_length=255) > > <snip> > Now I will access the table through django and save an empty string to > > the name field: > > >>> 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. You explicitly set the field to an empty string, so I can't think of any reason why it should somehow be converted to a null. ISTM this would be undesirable behaviour for almost all applications.
Rather than patch Django, you could subclass CharField to do the conversion, or simply override the model's save() method and do it there. -- DR. -- 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.