Hi,

I have a model roughly defined as such (FK fields do not appear for
simplicity):

class FieldChange(models.Model):
    old_value = models.CharField(max_length=50)
    new_value = models.CharField(max_length=50)

Using SQLite, the table definition roughly translates to:

CREATE TABLE "fieldchange" (
    "id" integer NOT NULL PRIMARY KEY,
    "old_value" varchar(50) NOT NULL,
    "new_value" varchar(50) NOT NULL,
)

However, it seems that the "max_length" condition is not respected,
neither at Django level (when saving) nor at database level:
For instance, I managed to create a model instance with fields longer
than 50 characters and save it.
Worse, I managed to retrieve that instance with fields unchanged, i.e
their size still exceeding 50 characters (in a separate "django shell"
session).

I expected the operation to fail at validation or DB backend level, or
at least that the fields would be truncated to comply with condition
"max_length=50". Is there some kind of bad magic here? Or only related
to SQLite?

Now what had me spot the error is that I wanted to manually truncate
'old_value' and 'new_value' fields when data exceeds the 50 characters
limit (adding trailing '...' characters when necessary). Where is the
best location to do that? The model 'save()' method, I suppose?

Thanks for any clarification.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to