django-postgres-extra icon indicating copy to clipboard operation
django-postgres-extra copied to clipboard

Composite primary keys?

Open onecrayon opened this issue 3 years ago • 3 comments

We are currently evaluating partitioned tables in Postgres for use with our logging database backing a Django application (large volume of log entries that are typically filtered by date, but we only keep six months worth of data). However, one of our requirements is being able to filter log entries out based on user access (users can share access with other users), and doing a many-to-many lookup table alongside the partitioned table seemed like a sensible approach to support this.

However, if we are understanding the Postgres documentation correctly, in order to make foreign key relationships into a partitioned table, the table needs to have a composite primary key that includes the date column used to establish the partition ranges. This is problematic because Django does not support composite primary keys.

Are there any known workarounds to allow this with django-postgres-extra?

I reviewed the documentation and checked other issues, but didn't find anything specifically relevant to this (#178 was the closest related issue I located), so any guidance is appreciated!

onecrayon avatar Sep 27 '22 18:09 onecrayon

Django does not support composite primary keys. You can create them manually in a migration using migrations.RunSQL.

Photonios avatar Feb 03 '23 08:02 Photonios

@onecrayon Were you able to implement partitioning? I'm facing the same issue but getting error https://github.com/SectorLabs/django-postgres-extra/issues/210

anuj-scanova avatar Apr 14 '23 09:04 anuj-scanova

Refer this thread -> https://github.com/SectorLabs/django-postgres-extra/issues/178

shubhammapara avatar Nov 15 '23 12:11 shubhammapara