Home > database >  How to define one to many relationship in django
How to define one to many relationship in django

Time:12-22

I have a condition that has one to many relationship scenarios because I will have multiple projects inside one account.

models.py

class Account(models.Model):
    name = models.CharField(max_length=255, default='')

class Project(models.Model):
    account = models.ForeignKey(User, on_delete=models.CASCADE, null=True)

how can I manage this scenario, currently I'm getting the following error:

django.db.utils.ProgrammingError: relation "project_account_id_7d9b231b" already exists

CodePudding user response:

account = models.ForeignKey(Account, on_delete=models.CASCADE, null=True)
  • Related