Django

Code

Ticket #4048 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

mysql introspection doesn't handle CHAR(n) fields

Reported by: Bill Fenner <fenner@gmail.com> Assigned to: adrian
Milestone: Component: Database wrapper
Version: 0.96 Keywords: mysql inspectdb
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

introspection.py.diff (278 bytes) - added by Bill Fenner <fenner@gmail.com> on 04/14/07 18:38:23.
Patch for db/backends/mysql/introspection.py
introspection.py-try-2.diff (430 bytes) - added by Bill Fenner <fenner@gmail.com> on 04/14/07 19:18:22.
A less incorrect diff for introspection.py

Change History

04/14/07 18:38:23 changed by Bill Fenner <fenner@gmail.com>

  • attachment introspection.py.diff added.

Patch for db/backends/mysql/introspection.py

04/14/07 18:49:49 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Ready for checkin.
  • needs_tests changed.
  • needs_docs changed.

04/14/07 19:18:22 changed by Bill Fenner <fenner@gmail.com>

  • attachment introspection.py-try-2.diff added.

A less incorrect diff for introspection.py

04/14/07 19:22:57 changed by Bill Fenner <fenner@gmail.com>

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.

04/20/07 05:04:20 changed by mtredinnick

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

04/20/07 05:05:39 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [5042]) Fixed #4048 -- When introspecting a MySQL database, map CHAR(n) fields to Django's CharField? type, not TextField?. Thanks, Bill Fenner.


Add/Change #4048 (mysql introspection doesn't handle CHAR(n) fields)




Change Properties
Action