Multiple fields primary keys in Django



I would use a default primary key (auto field), and use the meta class property, unique_together
class Hop(models.Model): migration = models.ForeignKey('Migration') host = models.ForeignKey(User, related_name='host_set') class Meta: unique_together = (("migration", "host"),)
It would act as a “surrogate” primary key column.
If you really want to create a multi-column primary key, look into this app

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.