I am using Django 1.6, and i want to use composite primary keys. I know that its not directly supported by Djnago. But is there any alternative or packages to implement that. Any help would be appreciated. Thanks.
Asked
Active
Viewed 2,962 times
0
-
possible duplicate of [Django or similar for composite primary keys](http://stackoverflow.com/questions/1624257/django-or-similar-for-composite-primary-keys) – Paulo Scardine Jul 01 '14 at 17:28
-
i already saw that...but i don't want any auto incremented key. – Shivratna Jul 01 '14 at 17:42
-
Possible duplicate of [Composite primary key in django](https://stackoverflow.com/questions/28712848/composite-primary-key-in-django) – bubbassauro Jun 25 '19 at 15:08
-
i've implemented basic support for virtual Composite Keys. No database modifications are required stackoverflow.com/a/65404017/46548 – kmmbvnr Dec 22 '20 at 06:34
1 Answers
1
You can use Django with SQLAlchemy instead of the native ORM for models where you need composite primary keys.
You will not be able to use the admin app with SQLAlchemy models without a surrogate key (this is probably the case with most of the Django ecosystem). You will also need a ModelForm replacement like WTForms.
If you need composite primary keys, take a look at Flask instead, You will be able to leverage most of your Django skills. It is very well documented and has a sizeable ecosystem.

Paulo Scardine
- 73,447
- 11
- 124
- 153
-
Thanks for your answer...but the requirement is to use PostgreSql and Django. – Shivratna Jul 01 '14 at 17:45
-
Django does not support SQLAlchemy natively but it can coexists seamlessly with Djangos ORM. I have used it in projects where I have to interface to a legacy database having composite primary keys. – Paulo Scardine Jul 01 '14 at 18:06
-
Thanks a lot. I would really appreciate an example for defining the composite primary keys using SQlAchemy with coexistance of Django model, as i have not used SQlAchemy ever. Thanks again. – Shivratna Jul 01 '14 at 19:07
-
Hii...i am waiting for your help. If you have some time please give me an example of what i mentioned above. It would be of great help. Thanks. – Shivratna Jul 08 '14 at 18:28