Skip to content

Commit 08392c8

Browse files
author
mtredinnick
committed
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 danodonovan. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16641 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent cb2c246 commit 08392c8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

django/core/management/commands/inspectdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def handle_inspection(self, options):
101101
att_name += '_field'
102102
comment_notes.append('Field renamed because it was a Python reserved word.')
103103

104+
if att_name.isdigit():
105+
att_name = 'number_%d' % int(att_name)
106+
extra_params['db_column'] = unicode(column_name)
107+
comment_notes.append("Field renamed because it wasn't a "
108+
"valid Python identifier.")
109+
104110
# Don't output 'id = meta.AutoField(primary_key=True)', because
105111
# that's assumed if it doesn't exist.
106112
if att_name == 'id' and field_type == 'AutoField(' and extra_params == {'primary_key': True}:

0 commit comments

Comments
 (0)