Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Many-to-many through a table with (only) compound key

I have a legacy database with a table storing a many-to-many relationship, but without a single primary key column. Is there any way to convince Django to use it anyway?

Schematically:

Product 1<---->* Labeling *<---->1 Label

The Labeling table uses (product_id,label_id) as a compound primary key, and I don't see any way to inform Django about this. (Just using through gives me Unknown column 'labeling.id' in 'field list'.)

Do I need to fall back to custom SQL? Or am I missing something?

like image 987
Tikitu Avatar asked Jun 22 '10 09:06

Tikitu


1 Answers

hope this helps you,

http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.db_index

like image 193
Ashok Avatar answered Oct 06 '22 01:10

Ashok