Opened 18 years ago
Closed 17 years ago
#4048 closed (fixed)
mysql introspection doesn't handle CHAR(n) fields
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 0.96 |
Severity: | Keywords: | mysql inspectdb | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a legacy table that has columns like
CREATE TABLE `foo_info` ( `foo_tag` int(11) NOT NULL auto_increment, `record_type` char(8) default NULL, `name_prefix` char(10) default NULL, `first_name` char(20) default NULL, ...
note: CHAR, not VARCHAR.
"python manage.py inspectdb" turns these into TextFields since it doesn't know any better. They work much better as CharFields; the attached diff makes that happen.
Attachments (2)
Change History (6)
by , 18 years ago
Attachment: | introspection.py.diff added |
---|
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
by , 18 years ago
Attachment: | introspection.py-try-2.diff added |
---|
A less incorrect diff for introspection.py
comment:2 by , 18 years ago
I missed that the STRING -> TextField mapping was done explicitly. I attached a new patch that changes the existing mapping instead of adding a new one at the end.
CharField is a much better match for STRING than TextField is. Neither one will exactly recreate the original schema with "python manage.py sql", but STRINGs are much closer to VAR_STRINGs than they are to BLOBs.
comment:3 by , 17 years ago
A bit subjective, this one, but I'm inclined to agree that CharField will be more appropriate. The backwards-incompat change is unlikely to bite anybody badly, either.
In future, please make patches from the route of the source tree so that we can see which file is patched (in this case, it's easy enough to work it out, but not always).
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch for db/backends/mysql/introspection.py