Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#8380 closed (invalid)

models.CharField 3 times the actually database field length

Reported by: hall Owned by: nobody
Component: inspectdb Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If I do python inspectdb for my project I get this output:

class DjangoSession(models.Model):
    session_key = models.CharField(max_length=120, primary_key=True)
    session_data = models.TextField()
    expire_date = models.DateTimeField()
    class Meta:
        db_table = u'django_session'

But session_key is varchar(40). I'd try and drop the table and run syncdb, it creates the same database structure but inspectdb still reports it as 3 times the length.

The database is MySQL, noticed it in django 0.96.2 and latest revision 8423.

Change History (2)

comment:1 Changed 10 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

This usually pops up when your database table encoding is latin1. Something (the MySQL client maybe?) notes that since we need to be able to store UTF-8 characters in there, it will need to save more bytes than just one per character. If your database table uses utf-8 encoding, it would report 40 characters there.

There's no real bug here, since it's not really possible to do all this detect and inspectdb is only meant as a guide in any case.

comment:2 Changed 10 years ago by anonymous

Here's the database's encoding, collation = utf8_general_ci

Server version:		5.0.60-log Gentoo Linux mysql-5.0.60-r1
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8
Db     characterset:	utf8
Client characterset:	utf8
Conn.  characterset:	utf8

The weird thing is that it just kind of happened, it use to work perfectly fine. And I really can't recall what could've made it change.

Note: See TracTickets for help on using tickets.
Back to Top