id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 12768 Raw query map problem with some primary keys Reflejo@… nobody "Hello, I'm trying the new raw query feature and i'm facing this bug: When my model has primary_key set to some ForeignKey and I try to invoke the raw() method, !InvalidQuery('Raw query must include the primary key') is raised. {{{ class ExampleModel(models.Model): some = models.ForeignKey(SomeOther, primary_key=True) class Meta: db_table = 'example_model' ExampleModel.objects.raw(""SELECT some_id FROM example_model"") }}} The problem arise because get_attname_column gives (some_id, some_id) as name/column but then it is compared to _meta.pk.attname (some) here: {{{ if skip: if self.model._meta.pk.attname in skip: raise InvalidQuery('Raw query must include the primary key') }}}" Uncategorized closed Database layer (models, ORM) dev Normal fixed Unreviewed 0 0 0 0 0 0