Opened 8 years ago
Last modified 8 years ago
#26667 closed Bug
Invalid query for OneToOneField if 'to_field' specified and primary_key=True — at Initial Version
Reported by: | Vitaliy Yelnik | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Release blocker | Keywords: | OneToOneField to_field primary_key |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given the following models:
class Model1(models.Model): str_id = models.CharField(max_length=12, unique=True) class Model2(models.Model): model1 = models.OneToOneField(Model1, to_field='str_id', primary_key=True)
In Django 1.9 query:
Model2.objects.filter(model1=instance_model1)
always returns an empty list, though in Django 1.8 works
Django 1.9 query
In [4]: print Model2.objects.filter(model1=model1).query SELECT "app_model2"."model1_id" FROM "app_model2" WHERE "app_model2"."model1_id" = 1
Django 1.8 query
In [4]: print Model2.objects.filter(model1=model1).query SELECT `app_model2`.`model1_id` FROM `app_model2` WHERE `app_model2`.`model1_id` = 1234567890ax
Note:
See TracTickets
for help on using tickets.