39
Django does not support compound primary keys. You can create a single compound unique key with Meta.unique_together
.
18
if you want only unique mixed fields together use belowcode:
class MyTable(models.Model):
class Meta:
unique_together = (('key1', 'key2'),)
key1 = models.IntegerField()
key2 = models.IntegerField()
But if you want unique together and one of column be primary, set primary
argument for model column, similar below code:
class MyTable(models.Model):
class Meta:
unique_together = (('key1', 'key2'),)
key1 = models.IntegerField(primary_key=True)
key2 = models.IntegerField()
- [Django]-Celery Flower Security in Production
- [Django]-How do I create a slug in Django?
- [Django]-What is StatReloader while running Django?
Source:stackexchange.com