Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#8573 closed (fixed)

inspectdb doesn't make use of FK and uniqueness information when the column name has upper case characters

Reported by: Ramiro Morales Owned by: nobody
Component: django-admin.py inspectdb Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

This was reported as an ​issue in the ​django-pyodbc project but after some debugging turned to be a bug in inspectdb.

Problem is it doesn't use the real database column name but rather a derived att_name value (used to represent the final Django model field name) when looking up the meta information about FK and indexes the DB backend provides via the DatabaseIntrospection.get_relations() method. This fails for database engines that are case sensitive (i.e. all but Oracle).

Also, because of a related problem, it can attempt to use that same innaccurate att_name instead of the real table column when trying to introspect the db_column field option.

Example:

This models.py file:

class Magazine(models.Model):
    ident = models.AutoField(primary_key=True, db_column='Ident')

class ReaderComment(models.Model):
    text = models.TextField(max_length=30, primary_key=True, db_column='reader_comment')

when syncdbed to the database (sqlite3) and the introspected back gives:

class IntrosBugMagazine(models.Model):
    ident = models.IntegerField()
    class Meta:
        db_table = u'intros_bug_magazine'

class IntrosBugReadercomment(models.Model):
    reader_comment = models.TextField(primary_key=True)
    class Meta:
        db_table = u'intros_bug_readercomment'

Note the ident field of the Magazine model is missing:

  1. The 'primary_key=True'option(that's because the syncdb command didn't make use of the 'primary_key': True info the database backend introspection support code correctly returned for it.)
  2. The db_column='Ident' option

Attachments (1)

inspectdb_fk_uppercase_fields.diff​ (2.0 KB ) - added by Ramiro Morales 18 years ago.

Download all attachments as: .zip

Change History (5)

by Ramiro Morales, 18 years ago

comment:1 by Ramiro Morales, 18 years ago

Has patch: set

comment:2 by Ramiro Morales, 18 years ago

Description: modified (diff)
Summary: inspectdb doesn't make use of FK information when the column name has upper case characters → inspectdb doesn't make use of FK and uniqueness information when the column name has upper case characters

comment:3 by Adrian Holovaty, 18 years ago

Resolution: → fixed
Status: new → closed

(In [9053]) Fixed #8573 -- Fixed bug in 'inspectdb' regarding case-sensitivity of field names. It was automatically lowercasing the column name to create the Field name, which was inaccurate in the case of column names that contained a capital letter. Thanks for reporting and detective work, ramiro

comment:4 by Adrian Holovaty, 18 years ago

Note that I ended up using *most* of the patch, but it was missing a crucial element -- the part in syncdb that set db_column if column_name != att_name.

Also note that I've alerted the guys downstream in django-pyodbc -- ​http://code.google.com/p/django-pyodbc/issues/detail?id=12

Note: See TracTickets for help on using tickets.
Back to Top