Search code examples
djangodjango-modelsdjango-migrations

Getting error DecimalFields must define a 'max_digits' attribute


I'm having a problem with these DecimalField types.

I have the next model:

class Mediciones(models.Model):
    id = models.AutoField(primary_key=True)
    nombre = models.CharField(max_length=30, verbose_name='Nombre dispositivo')
    dispositivo = models.ForeignKey(Dispositivos, on_delete=models.CASCADE)
    temperatura = models.DecimalField(max_digits=5, decimal_places=2)
    humedad = models.DecimalField(max_digits=5, decimal_places=2)
    ruido = models.DecimalField(max_digits=7, decimal_places=2)
    c02 = models.DecimalField(max_digits=7, decimal_places=2)
    alerta = models.BooleanField(null=False)
    fecha = models.DateTimeField(verbose_name="Fecha", blank = False)

As you can see, I have four DecimalField, and all of them have defined both "max_digits" and "decimal_places", and max_digits is greater than decimal_places. Despite of that, I'm getting errors "DecimalFields must define a 'max_digits' attribute." when I try to make a migration. Do you know why?

Thanks in advance!


Solution

  • In the end I have managed to solve. The problem was not with the syntax, it seemed to be with the Python cache. I realized that when changing some fields it kept coming out (although I deleted the ones that gave error), so I assumed that I was not checking the file. I deleted the "pychache" and "migrations" folders, did a new migration and it worked.