#17676: inspectdb generates invalid field name for tables that start with a number --------------------------------------------+-------------------- Reporter: Gandalfar | Owner: nobody Type: Bug | Status: new Component: Core (Management commands) | Version: SVN Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 1 Easy pickings: 0 | UI/UX: 0 --------------------------------------------+-------------------- Ticket #16536 introduces patch that fixes this for fields that are numbers. It turns out that some people start their table names with numbers (e.g.: '3starost') and Django doesn't like that.
This patch extends current functionality by making sure that first character of table isn't a digit: {{{ --- a/django/core/management/commands/inspectdb.py +++ b/django/core/management/commands/inspectdb.py @@ -101,8 +101,8 @@ class Command(NoArgsCommand): 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) + if att_name[0].isdigit(): + att_name = 'number_%s' % att_name extra_params['db_column'] = unicode(column_name) comment_notes.append("Field renamed because it wasn't a " "valid Python identifier.") }}} Original patch didn't have a test and I'm not sure how actually test this within Django framework, but I'm happy to write one I someone can give me hint where to start, if it's required. -- Ticket URL: <https://code.djangoproject.com/ticket/17676> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.