I'm trying to connect Django with PostgreSQL, so far everything was going good, I created a model for female clients
from django.db import models
from django.db.models import CheckConstraint, Q
class fml_tbl(models.Model):
fml_id = models.CharField(primary_key = True, max_length = 10)
first_name = models.CharField(max_length = 20, null = False)
last_name = models.CharField(max_length = 20)
age = models.PositiveIntegerField(unique = True)
qualification = models.CharField(max_length = 50)
profession = models.CharField(max_length = 50)
officer = models.ForeignKey("officer", on_delete=models.CASCADE, null = False)
class Meta:
constraints = [
models.CheckConstraint(check=Q(age__gte=18), name='age_gte_18')
]
I added a check constraint for checking the age of the client, when I migrate, I get the error...
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (models.E032) constraint name 'age_gte_18' is not unique amongst models: client.fml_tbl, client.ml_tbl.
System check identified 1 issue (0 silenced).
there is also a male clients table same as this one, i'm just trying to practice django model constraints because postgresql also uses constraints, but i can't understand what to do here. I'm using Django 3.0 and Python 3.7
I searched for different answers on stackoverflow and other places but i can't find anything, I used the django documentation and this site for understanding constraints but so far this is all what the documentation says about my error, and this is the only SO answer I find on CheckConstraints, but this doesn't solve my problem.
Kindly help me out, and explain it as simply as possible because i'm a newbie. I'll really appreciate the help!