Opened 16 years ago
Closed 15 years ago
#11199 closed (invalid)
Select_related added to the query set will produce empty result
Reported by: | milosu | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
You have a model like:
class Driver: name = models.CharField(max_length=100) class Car: name = models.CharField(max_length=100) driver = models.ForeignKey(Driver)
Inside the database mangle the fkey from car to driver as nullable and insert some records into car table without the reference to the driver table.
Than just try:
Car.objects.filter(name = 'something').select_related()
and you will get empty queryset when evaluated.
I guess this is a correct ORM behaviour when using inner joins etc.
Could this be documented somewhere? It was quite mysterious for me to make an observation like this and to find the problem (missing null=True model declaration)..
Change History (2)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|
comment:2 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Marking as invalid, your Models need to match your DB.
Please use preview.