aaravam aaravam - 22 days ago 7
MySQL Question

Can't migrate Django app - MySQL throws an OperationalError "Too big scale specified"

I am trying to connect my Django app to a MySQL database. I created the database, and tried migrating the app with

python manage.py migrate
. At this point I get the following error:

django.db.utils.OperationalError: (1425, "Too big scale 100 specified for column 'score'. Maximum is 30.")


I checked that object in
models.py
. It looks like this:

class Para(models.Model):
...
text = models.CharField(max_length=20000)
score = models.DecimalField(max_digits=100, decimal_places=5)

def __unicode__(self):
return self.text[:20]


So I changed the
max_digits
to 20, ran
makemigrations
and tried migrating again. But I keep getting the same error. I am new to MySQL, and not sure what I am doing wrong.

Any help much appreciated. Thanks!

Answer

Changing that to

score = models.DecimalField(max_digits=20, decimal_places=5)

Followed by another makemigrations will not work (as you have already found out) because the previous migration is what your server is choking on. The simplest solution, delete the two most recent migrations (assuming that you have not made any other changes). Then run

./manage.py makemigrations
./manage.py migrate
Comments