﻿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
36092	Composite primary key wrongly allows non-local fields to be referenced	Jacob Walls	Csirmaz Bendegúz	"(As ever, let me know if this is a known/deferred issue--just trying to report anything I noticed while taking a look around.)
----
With these models:

{{{#!py
class CoffeeProduct(models.Model):
    whole_bean = models.BooleanField()


class SpecialtyCoffeeProduct(CoffeeProduct):
    pk = models.CompositePrimaryKey(""whole_bean"", ""varietal"")
    varietal = models.CharField()
}}}

This migration is generated on sqlite:
{{{#!sql
BEGIN;
--
-- Create model CoffeeProduct
--
CREATE TABLE ""appName_coffeeproduct"" (""id"" integer NOT NULL PRIMARY KEY AUTOINCREMENT, ""whole_bean"" bool NOT NULL);
--
-- Create model SpecialtyCoffeeProduct
--
CREATE TABLE ""appName_specialtycoffeeproduct"" (""coffeeproduct_ptr_id"" bigint NOT NULL UNIQUE REFERENCES ""appName_coffeeproduct"" (""id"") DEFERRABLE INITIALLY DEFERRED, ""varietal"" varchar NOT NULL, PRIMARY KEY (""whole_bean"", ""varietal""));
COMMIT;
}}}

And fails when executed:
{{{
  File ""/Users/<user>/django/django/db/backends/sqlite3/base.py"", line 356, in execute
    return super().execute(query)
           ^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: expressions prohibited in PRIMARY KEY and UNIQUE constraints
}}}"	Bug	closed	Database layer (models, ORM)	dev	Release blocker	fixed	compositeprimarykey	Csirmaz Bendegúz	Ready for checkin	1	0	0	0	0	0
