django.db.utils.IntegrityError: UNIQUE constraint failed: cedente.cnpj (django)

After I delete a Cedente if I try to create another one with the CNPJ of the previous one, I have this error:

django.db.utils.IntegrityError: UNIQUE constraint failed: cedente.cnpj

this is the model:

class Cedente(BaseModel):
    class Meta:
        
        db_table = 'cedente'
        verbose_name = "cedente"
        verbose_name_plural = "cedentes"
    
    razao_social = models.CharField(max_length=100, unique=True, verbose_name="Razão Social")
    nome = models.CharField(max_length=100, verbose_name="Nome Padrão")
    cnpj = models.CharField(max_length=14, validators=[validate_CNPJ], unique=True, verbose_name="CNPJ")
    nome_contato = models.CharField(max_length=100, verbose_name="Nome")
    ddd_telefone_contato = models.CharField(max_length=2, verbose_name="DDD", validators=[validate_int, validate_length_ddd])
    numero_telefone_contato = models.CharField(max_length=9, verbose_name="Telefone", validators=[validate_int, validate_length_telefone])
    email_contato = models.CharField(max_length=50, verbose_name="E-mail", validators=[validate_email])
    calculo = models.ForeignKey(Calculo, verbose_name="Cálculo", related_name='cedentes', on_delete=models.CASCADE, null=True)
    commissao = models.ForeignKey(Commissao, verbose_name="Comissão", related_name='cedentes', on_delete=models.CASCADE, null=True)

    def __str__(self):
        return ("%s (ID: %d)" % (self.nome, self.id))


from Recent Questions - Stack Overflow https://ift.tt/36dJEh0
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation