On 5/4/2009 8:46 AM, MS wrote:
> I have a problem with django+postgresql:
> I have a model with a CharField(max_length=255) field, and I'm
> assigning some much longer value to this field, like:
> 
> m = MyModel()
> m.myfield = 'very long text - say 400 chars'
> m.save()
> 
> In save() I'm getting an error "ERROR:  value too long for type
> character varying(255)", and the SQL statement contains the 'very long
> text - say 400 chars' intact.
> 
> I thought that if django knows that a field is restricted to 255
> chars, then it will validate it and
> truncate excessive chars before saving. But it doesn't. How can I get
> rid of that problem?

If you want that behavior, just truncate `myfield` in `MyModel.save()` 
before calling the super save.

<http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.save>

-- 
George

--~--~---------~--~----~------------~-------~--~----~
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