inspectdb does not properly handle renamed fields for unique_together
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)
Triage Stage: |
Unreviewed → Accepted
|
Type: |
Uncategorized → Bug
|
Owner: |
changed from nobody to Anderson Resende
|
Status: |
new → assigned
|
Owner: |
Anderson Resende removed
|
Status: |
assigned → new
|
Owner: |
set to Tim Graham <timograham@…>
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Patch submitted in: https://github.com/django/django/pull/5562