IntegrityError at /admin/base/client/1/delete/ on django

when I try deleting an object from the admin panel in my django app in the database it raises an exception that reads:

IntegrityError at /admin/base/client/1/delete/ 
FOREIGN KEY constraint failed

I have looked it up and couldn't find the reason to why this is happening...

here is the model in models.py:

class Client(models.Model):
    name = models.CharField(max_length=200, null=True, blank=True)
    last_name = models.CharField(max_length=200, null=True, blank=True)
    email = models.EmailField(unique=True, null=True, blank=True)
    company = models.ForeignKey(Company, on_delete=models.DO_NOTHING, null=True)
    phone_number = models.CharField(max_length=200, null=True, blank=True)
    is_active = models.BooleanField(default=False)
    is_new = models.BooleanField(default=True)
    created = models.DateField(default=timezone.now)
    users = models.ManyToManyField(User, related_name='user', blank=True)
    # files = 
    def __str__(self):
        return f'{self.phone_number}'

Thank you for your help.

I figured out the problem.

I had another model that had the Client model's client.name attribute as its __str__ method. removed it from there and the problem was solved.

Back to Top