Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using 'old' database with django

Tags:

python

django

I'm using a hand built (Postgres) database with Django. With "inspectdb" I was able to automatically create a model for it. The problem is that some tables have multiple primary keys (for many-to-many relations) and they are not accessible via Django.

What's the best way to access these tables?

like image 200
Jack Ha Avatar asked Mar 24 '09 13:03

Jack Ha


People also ask

Can Django use existing database?

Django provides a utility to auto-generate models from an existing database via inspectdb command. The output file will be saved to your current directory. Move that file to the correct app and you have a good starting point for further customization.

Which DB works best with Django?

MySQL and PostgreSQL work best with Django.


1 Answers

There is no way to use composite primary keys in Django's ORM as of now (up to v1.0.2).

I can only think of three solutions/workarounds:

  1. There is a fork of django with a composite pk patch at github that you might want to try.
  2. You could use SQLAlchemy together with Django.
  3. You have to add a single field primary key field to those tables.
like image 81
Haes Avatar answered Oct 04 '22 01:10

Haes