Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25274 closed Bug (fixed)

inspectdb does not properly handle renamed fields for unique_together

Reported by: John Moore Owned by: Tim Graham <timograham@…>
Component: Core (Management commands) Version: 1.8
Severity: Normal Keywords: inspectdb, unique_together
Cc: timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When I last used inspectdb, a field named "from" in a table was renamed automatically to "from_field." There was a comment in the output: "Field renamed because it was a Python reserved word." But for the unique_together meta property for that model, the "from" field name was used, not the "from_field" name. Thus I received an error when using runserver: "'unique_together' refers to the non-existent field 'from'."

The original issue for adding unique_together support is #23028, I believe.

Here's an example of what I mean:

class PsSpecificPrice(models.Model):
    . . .
    from_field = models.DateTimeField(db_column='from')  # Field renamed because it was a Python reserved word.
    to = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'ps_specific_price'
        unique_together = ((. . . 'from', 'to'),)

Change History (8)

comment:1 by Claude Paroz, 9 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 by Anderson Resende, 9 years ago

Owner: changed from nobody to Anderson Resende
Status: newassigned

comment:3 by Jacek Bzdak, 9 years ago

Has patch: set

comment:4 by Anderson Resende, 9 years ago

Owner: Anderson Resende removed
Status: assignednew

comment:5 by Tim Graham <timograham@…>, 9 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 2cb50f93:

Fixed #25274 --- Made inspectdb handle renamed fields in unique_together.

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 834ad414:

[1.8.x] Fixed #25274 --- Made inspectdb handle renamed fields in unique_together.

Backport of 2cb50f935aa70e91dd6c2f253becd636a2eb6fb7 from master

comment:7 by Tim Graham <timograham@…>, 9 years ago

In 023bf66b:

[1.9.x] Fixed #25274 --- Made inspectdb handle renamed fields in unique_together.

Backport of 2cb50f935aa70e91dd6c2f253becd636a2eb6fb7 from master

comment:8 by Tim Graham <timograham@…>, 9 years ago

In 6914a716:

[1.8.x] Refs #25274 -- Added missing argument to contrib.gis' inspectdb.

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