Dear Djangonauts, I have read the documentation and I think I understand why we don't want to store empty strings as NULL in the database.
I also understand that model validation is being worked on and it's not what I'm trying to achieve here. The question of why CharField default to empty strings has already been discussed a couple of years ago on this mailing list, without any conclusive answer: http://groups.google.com/group/django-developers/browse_thread/thread/681a64eeb905da05/1ccd44ea84df1258?lnk=gst&q=empty+string#1ccd44ea84df1258 In this thread Malcolm Tredinnick explain that the choice of null=False has been made because it makes more sense in the context of a web form. This makes sense to me. But considering this model and it's model form: class Contact(models.Model): name = models.CharField(max_length=255) message = models.TextField() def __unicode__(self): return u'name: %s, message: %s' % (self.name, self.message) class ContactForm(forms.ModelForm): class Meta: model = Contact and the following script: from contactus.models import Contact, ContactForm Contact.objects.create() <Contact: name: , message: > ContactForm({}).errors {'message': [u'This field is required.'], 'name': [u'This field is required.']} I'm making the following observations: 1. When passed empty values, only the form raises a ValidationError. 2. If I add default=None to the model both raise an exception (ValidationError or IntegrityError). 3. If instead I set blank=True none of them raise any exception. So my question is: Since CharField (and childs) default to blank=False, why don't they have default=None as well? I believe this would be more consistent with FloatField and IntegerField for instance, what am I missing? -- Djoume -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=.
