On Mon, Feb 1, 2010 at 11:32 PM, Mike <[email protected]> wrote:

> Hi,
>
> I've tried to import my legacy MySQL database using
>
>  python manage.py inspectdb --database=myolddb >>models.py
>
> and found that all varchar(N) fields became models.CharField
> (max_length=3*N,...)
> i.e. three times longer. Is it a bug or an expected behavior?
> BTW I use trunk rev. 12374 and DEFAULT CHARSET for the table is utf-8.
>

It's a bug, somewhere.  See:

http://code.djangoproject.com/ticket/5725

Problem is it not clear where the bug is. Django is assuming the
'internal_size' element of the tuple returned from a cursor description call
for a a character column is the max size in characters. MySQLdb appears to
be returning the max size in bytes on the connection where the call was
made. Since Django always uses utf-8 for the connection, and MySQL doesn't
implement 4-byte utf-8 support, MySQLdb's answer is 3x the maximum character
count, since each character may take up to 3 bytes to encode in utf-8. I
can't find anyplace in the PEP249 spec that defines what, exactly, this
'internal_size' item is supposed to be returning.

Karen

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