Opened 18 years ago

Closed 14 years ago

#4212 closed Bug (invalid)

badly-defined ForeignKey to self does not cause an exception

Reported by: Forest Bond <forest@…> Owned by: Jonas Obrist
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a model something like this:

class MyModel(models.Model):
    my_model = ForeignKey('MyModel')

This mostly works, but I was confused when I found that instances didn't have a my_model_set attribute. I found that I should've defined my model like this:

class MyModel(models.Model):
    my_model = ForeignKey('self')

I can do that just fine, of course, but it was a bit non-obvious what the problem was. It'd be nice if defining that relationship improperly threw an exception.

Change History (6)

comment:1 by James Bennett, 18 years ago

Triage Stage: UnreviewedAccepted

Unfortunately it's kind of tricky to catch because that form is legal for getting around forward references to as-yet-undefined model classes, and for dealing with circular model dependencies. Probably still a good idea to see if we can do anything about it, though.

comment:2 by Philippe Raoult, 17 years ago

i'd say we should force related_name to be set for foreignkeys to self.

comment:3 by Ramiro Morales, 17 years ago

#3914 was about the same issue, marked as duplicate

comment:4 by Łukasz Rekucki, 14 years ago

Severity: Normal
Type: Bug

comment:5 by Jonas Obrist, 14 years ago

Easy pickings: unset
Owner: changed from nobody to Jonas Obrist
UI/UX: unset

comment:6 by Jonas Obrist, 14 years ago

Resolution: invalid
Status: newclosed

Can't reproduce this issue, works fine for me.

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