primary key django model
class Garden(models.Model):
garden_id = models.IntegerField(primary_key=True)
primary key django model
class Garden(models.Model):
garden_id = models.IntegerField(primary_key=True)
create models in django
from django.db import models
# Create your models here.
class Contact(models.Model):
name = models.CharField(max_length=50)
email = models.CharField(max_length=50)
contact = models.CharField(max_length=50)
content = models.TextField()
def __str__(self):
return self.name + ' ' + self.email
django id
The ID in django is a "unique identifier" for each models instances.
You do not need to explicitly add a ID field to your own models as
the ID attribute is automatically generated for you behind the scences
by django for each new model and any newly created instances of that
model afterwards.
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()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us