﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6344	Refactored manage.py inspectdb	Daniel Pope <dan@…>	nobody	"I have inherited a database developed in Microsoft Access that contains 1985 columns in 85 tables.

To import this into Django, I tried the existing inspectdb tool, but I found numerous bugs that would be too time-consuming to fix manually.

I have refactored the inspectdb tool to do a better job of importing. Aside from better ensuring that output is syntactically valid, the tool now constructs object-oriented structure which is then post-processed and serialized, rather than serializing on-the-fly. This approach makes it easier to procedurally rename models, and to include heuristics to fix up semantic problems with the models.

 * model class names are sanitized and converted to CamelCase
 * model field names are sanitized and converted to lowercase_with_underscores
 * db_column is '''always''' specified: this allows refactoring of field names in the generated code
 * no comment is issued where field names differ from database column names. This should now be assumed for all fields but the use of db_column makes this explicit
 * AutoFields are always explicit: again, this is useful when refactoring
 * blank lines are added in the output, so that fields definitions are visually grouped into keys, relations and other fields
 * write a warning comment if no primary_key is detected, as such models cannot be used with Django

I've added the following heuristics. These heuristics are not guaranteed to produce the right results, but they should produce the right results more often than if they were not included. For very large database schemas this is very important.

 * heuristically detect field names that are potentially keys but not defined as such, grouping these too (this is safe)
 * if no primary key is set, heuristically choose a candidate field if one matches the name of the model (this is unsafe but a warning comment is issued; besides, the alternative cannot work)
 * heuristically, upgrade IntegerFields with primary_key=True to AutoField if there is none (this is unsafe. A warning comment is issued.)

This tool still does not guarantee to resolve conflicts between field or model names (a very insidious issue should it occur), although the refactor was designed partly this this goal in mind.
"	Bug	closed	Core (Management commands)	dev	Normal	wontfix	inspectdb		Accepted	1	0	1	1	0	0
