Opened 4 years ago

Closed 4 years ago

#16316 closed Bug (duplicate)

Error with GenericRelation applied to a subclass

Reported by: jordanreiter@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I noticed this when using the django-threadedcomments app and trying to add a GenericRelation pointing to the ThreadedComment model. I would assume this holds true for any model that subclasses a model with generic foreign keys.

class Discussion(models.Model):
    title = models.CharField(max_length=100, help_text='Enter a descriptive title for this discussion.')
    content = models.TextField(null=True, blank=True)
    date = models.DateTimeField()
    comments = generic.GenericRelation(ThreadedComment)

And then

>>> Discussion.objects.filter(comments__isnull=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/path/to/django/db/models/", line 69, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/path/to/django/db/models/", line 84, in __len__
  File "/path/to/django/db/models/", line 273, in iterator
    for row in compiler.results_iter():
  File "/path/to/django/db/models/sql/", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/path/to/django/db/models/sql/", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/path/to/django/db/backends/mysql/", line 86, in execute
    return self.cursor.execute(query, args)
  File "/srv/python-environments/academicexperts/lib/python2.7/site-packages/MySQLdb/", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/srv/python-environments/academicexperts/lib/python2.7/site-packages/MySQLdb/", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'threadedcomments_comment.object_id' in 'on clause'")

Change History (1)

comment:1 Changed 4 years ago by manfre

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #9899 (GenericRelation of a childmodel can't be used in lookup) and #12885 (GenericRelation fails to join the related table from a inherited model)

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