Buy Tickets
Starting from 350€
Support unavailable
Please try again later

Composite Key is ready for Django 1.4

by Simone Federici - Michal Petrucha for EuroPython 2012

Currently Django models only support single column primary keys.

Multi-column primary keys support would improve Django integration with legacy databases (whose schema cannot be changed and usualy have multi-column primary keys).

This project allows the usage of django ORM with Multi-Column Primary Key and includes Foreign Key support.

In this talk we will explain the problem, propose a solution and present two projects aiming to solve it.

One of them is a pluggable app which monkey-patches Django’s ORM. Its obvious benefit is you can introduce it in a project without maintaining an unofficial Django fork.

The other one is the long-term solution approved of by the Django core team. It was part of last year’s Google Summer of Code and we will talk about what is ready and what is yet to be done before it is included into mainline Django.

in on Friday 6 July at 09:45 See schedule



  1. Gravatar
    I have not watched the video, but I am wondering if there is a solution available as a "monkey patch" pluggable app as described in the abstract to the talk at EuroPython 2012.

    Better yet, is an official solution available in Django itself?

    I would like to use Django with some legacy/warehouse databases, but they ALL use composite keys.

    Thanks for any feedback, suggestions, etc.

  2. Gravatar
    If you can add a column to every table, you can use the fake system using unique together with the keys and id, in the new column.

    but you cannot use the django join table orm system.

    For the official support, you have to help Michal to implement the CFK feature.

    If you need a quick solution as described in the abstract, use my library. It Is not official, is not completed, is not stable, but if you don0t use "django generic features" (not you case) it have to work. If you have problem contact me directly.

    Here the django ticket:

    The django wiki page:

    Here my monkeypatch project:

    Here Michal django fork.
  3. Gravatar
    Yeah, about an official solution... The project is still work in progress. We made some serious advanced during the EuroPython sprints but lately I've had problems catching up with changes upstream related to Py3k compatibility.

New comment

45 minutes

Tagged as

database community django api design architecture sql
Our Sponsors
Python Experts
Personnel development with 360° feedback
SSL Matrix
Wanna sponsor?