Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

69
Visualizações
Local field 'created_at' in class 'Attachment' clashes with field of similar name from base class 'Timestampable'

I have the following two models:

class Timestampable(models.Model):
    created_at = models.DateTimeField(null=True, default=None)
    updated_at = models.DateTimeField(null=True, default=None)

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        now = timezone.now()
        if not self.created_at:
            self.created_at = now
        self.updated_at = now

        super(Timestampable, self).save(*args, **kwargs)

class Attachment(Timestampable, models.Model):
    uuid = models.CharField(max_length=64, unique=True)
    customer = models.CharField(max_length=64)
    user = models.CharField(max_length=64)
    file = models.FileField(upload_to=upload_to)
    filename = models.CharField(max_length=255)
    mime = models.CharField(max_length=255)
    publicly_accessible = models.BooleanField(default=False)

When I try to migrate these models, I get the following error:

django.core.exceptions.FieldError: Local field 'created_at' in class 'Attachment' clashes with field of similar name from base class 'Timestampable'

I read here, here, and here that this should work when the base class is abstract. However, I marked it as abstract it still it doesn't seem to work. What else could be wrong? I am using Django 1.8.14.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Because your Timestampable model already extends from models.Model. You don't need extend Attachment model.

please use:

class Attachment(Timestampable):

instead of:

class Attachment(Timestampable, models.Model):
over 4 years ago · Santiago Trujillo Relatório

0

I found what was the problem. I used to have the class Timestampable not inherit from models.Model. Therefore, in one of my initial migrations, I had the line:

bases=(at_common.behaviours.Timestampable, models.Model),

I was looking for a way to remove this. Turned out that I just had to delete this line from the initial migration file.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda