The answer is No. Only single-column primary keys are supported. Django primarily uses single-column primary keys for its models. However, starting from Django version 1.11, you can use a combination of fields as a composite or multiple-column primary key using the primary_key argument in the model’s Meta class. Here’s an example:
from django.db import models
class MyModel(models.Model):
field1 = models.IntegerField()
field2 = models.CharField(max_length=50)
class Meta:
# Define a composite primary key using multiple fields
primary_key = ('field1', 'field2')
Add Comment