Opened 5 years ago

Closed 5 years ago

Last modified 5 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 Changed 5 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 5 years ago by Anderson Resende

Owner: changed from nobody to Anderson Resende
Status: newassigned

comment:3 Changed 5 years ago by Jacek Bzdak

Has patch: set

comment:4 Changed 5 years ago by Anderson Resende

Owner: Anderson Resende deleted
Status: assignednew

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

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

In 2cb50f93:

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

comment:6 Changed 5 years ago by Tim Graham <timograham@…>

In 834ad414:

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

Backport of 2cb50f935aa70e91dd6c2f253becd636a2eb6fb7 from master

comment:7 Changed 5 years ago by Tim Graham <timograham@…>

In 023bf66b:

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

Backport of 2cb50f935aa70e91dd6c2f253becd636a2eb6fb7 from master

comment:8 Changed 5 years ago by Tim Graham <timograham@…>

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