Advanced SQL Question

35 views
Skip to first unread message

G Z

unread,
Jun 19, 2014, 5:49:52 PM6/19/14
to django...@googlegroups.com
I have a multi-level database that uses concatenated foreign keys as primary keys for tables. 

For example we have three tables
VMS
VM_LICENSE
LICENSES


VMS has
name 
license_id <- foreign key
vm_id <-primary key


vm_licenses has two concatenated fkeys to for a primary key of:
licenses_id fkey to licenses
vm_id   fkey to vms


licenses has:

license_id pkey
product_code


how do I deal with concatenated foreign keys to form a primary key how do i even register that in the models.py? 
The reason I ask is because one i need to register them and the second is how do i save forms based on a concatinated pk

Javier Guerra Giraldez

unread,
Jun 19, 2014, 5:54:09 PM6/19/14
to django...@googlegroups.com
On Thu, Jun 19, 2014 at 4:49 PM, G Z <zuk...@gmail.com> wrote:
> how do I deal with concatenated foreign keys to form a primary key how do i
> even register that in the models.py?


i guess you mean composite keys. if so, then no; the Django ORM
doesn't support composite primary keys.

--
Javier

Martin Torre Castro

unread,
Jul 19, 2014, 8:55:41 PM7/19/14
to django...@googlegroups.com
I suppose you can always switch to the raw SQL queries instead of using Django's ORM. 

You have to type more, but it will be more efficient if you know how to code SQL for your DB.
Reply all
Reply to author
Forward
0 new messages