0

I've created views in my Postgres Database that have links in Django Rest Framework. enter image description here

I have about 20 views altogether. On 7 of them - I keep getting this programming error:

ProgrammingError at /api/reports/
column report.event_type_id_id does not exist
LINE 1: SELECT "report"."id", "report"."ev...

All 7 have the same exact error message. All of the views are based off one table with all the same column names. The column referenced in the table is event_type_id. NOT event_type_id_id. So I'm not sure where it's getting that from. If it had the same error on all of them - it would make a little more sense but it's only 7.

I'm not sure where to begin even correcting this issue because I can't pinpoint what the exact problem is. I'm assuming it's on the database side and how django expects to receive something from the database - but I'm not entirely sure. Any ideas??

Thanks in advance!

UPDATE: Exception Location:

/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py in execute
    def execute(self, sql, params=None):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
                return self.cursor.execute(sql)
            else:
                            return self.cursor.execute(sql, params) ...
    def executemany(self, sql, param_list):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            return self.cursor.executemany(sql, param_list)

Report Model Update:

class Report(models.Model):
    event_type_id = models.ForeignKey(EventTypeRef, default='01')
    event_at = models.DateTimeField("Event Time")
    xxxxxx_id = models.ForeignKey(xxxxxx)
    xxxx = models.BigIntegerField(blank=True, null=True)
    color = models.IntegerField(blank=True, null=True)
    xxxxx_info = models.CharField(db_column='xxxxxInfo', max_length=56, blank=True)
    xxxx_tag = models.ForeignKey(xxxxxxxx, blank=True, null=True)
    hidden = models.BooleanField(default=False)

    def __unicode__(self):              # __unicode__ on Python 2
        return self.event_type_id

    class Meta:
        managed= False,
        db_table = u'report'
        verbose_name_plural = "XXXXX Reports"
2
  • Could you post the Report model, please? Commented Jan 6, 2016 at 16:15
  • Just added it. All of the views pretty much have this same format. Thanks! Commented Jan 6, 2016 at 16:28

1 Answer 1

1

According to the Django ForeignKey documentation:

Behind the scenes, Django appends "_id" to the field name to create its database column name. In the above example, the database table for the Car model will have a manufacturer_id column. (You can change this explicitly by specifying db_column) However, your code should never have to deal with the database column name, unless you write custom SQL. You’ll always deal with the field names of your model object.

So, you should rename event_type_id to event_type

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.