Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Teach inspectdb to handle SQL column names that are digits.

There's no accounting for taste in the way some people name columns,
apparently. Create a column with a name of "1" and inspectdb will still
produce valid Python code now. Fixed #16536. Thanks tereaom and

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8560a2c08030d67e234112b6951279de205b4778 1 parent e3cd0e6
@malcolmt malcolmt authored
Showing with 6 additions and 0 deletions.
  1. +6 −0 django/core/management/commands/
6 django/core/management/commands/
@@ -101,6 +101,12 @@ def handle_inspection(self, options):
att_name += '_field'
comment_notes.append('Field renamed because it was a Python reserved word.')
+ if att_name.isdigit():
+ att_name = 'number_%d' % int(att_name)
+ extra_params['db_column'] = unicode(column_name)
+ comment_notes.append("Field renamed because it wasn't a "
+ "valid Python identifier.")
# Don't output 'id = meta.AutoField(primary_key=True)', because
# that's assumed if it doesn't exist.
if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}:
Please sign in to comment.
Something went wrong with that request. Please try again.