[Answered ]-Django inspectdb 'unique_together' refers to the non-existent field

2👍

This was a bug in Django 1.8, see #25274. It has been fixed in 1.8.8. You should upgrade to the latest 1.8.x version.

Note that minor version upgrades, from 1.8.x to 1.8.x+1, only include bugfixes and security updates. You should always aim to use the latest minor version. Only major version upgrades, from 1.Y to 1.Y+1, may break compatibility as outlined in the deprecation timeline.

👤knbk

0👍

django’s inspectdb took my legacy field names as the field names for unique_together. I changed this so it used the properties in the model, and that solved the problem. I also added the _ before the id, as stated in the google groups post listed above. But I am not sure if that underscore was relevant. Right now, I don’t want to mess with my set up, so I leave the test with the underscores (or rather without underscores) to someone else. 🙂 If I have time to test that, I will post what I find here.

Here is my working model code:

class Pagescanannotationscommentaries(models.Model):
    pagescanannotation_id = models.IntegerField(db_column='pageScanAnnotationId')  # Field name made lowercase.
    commentary_id = models.IntegerField(db_column='commentaryId')  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'PageScanAnnotationsCommentaries'
        unique_together = (('pagescanannotation_id', 'commentary_id'),)

This change made the error message disappear.

Leave a comment