Skip to content Skip to sidebar Skip to footer

Django Models And Primary-foreign Key Relationships

I'm writing a Django app that uses existing legacy data combined with a remapping of tables and relationships. I've been given a table containing the primary-foreign key relations

Solution 1:

From what I read, unique_together basically simulates a composite key and allows more than one field to have primary key functionality. Am I on the right track?

Not quite. It just adds a composite UNIQUE KEY to the specified fields, and only really has any effect during the creation of the table, which won't apply if you're using Django to access a legacy table. There's still no support for composite PRIMARY KEYs in Django (see bug #373).

Unfortunately, this probably means that you won't be able to use Django with a legacy table which has a composite PRIMARY KEY, without modifying the table to include a Django-compatible PRIMARY KEY, i.e. a key on a single, unique, field.

See also this question.

Post a Comment for "Django Models And Primary-foreign Key Relationships"