Answers for "primary key in django models"

3

primary key django model

class Garden(models.Model):
    garden_id = models.IntegerField(primary_key=True)
Posted by: Guest on April-29-2020
0

django composite primary key

#Try similar below code:

class MyTable(models.Model):
    class Meta:
        unique_together = (('key1', 'key2'),)

    key1 = models.IntegerField(primary_key=True)
    key2 = models.IntegerField()
#or if you want only unique mixed fields:

class MyTable(models.Model):
    class Meta:
        unique_together = (('key1', 'key2'),)

    key1 = models.IntegerField()
    key2 = models.IntegerField()
Posted by: Guest on August-26-2021

Code answers related to "primary key in django models"

Python Answers by Framework

Browse Popular Code Answers by Language