When I write a Python/Django class like:
class MyClass(models.Model):
price = models.DecimalField(..., max_digits=5, decimal_places=2)
I get the following error when running python manage.py makemigrations
:
ValueError: Cannot serialize: Ellipsis
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/2.0/topics/migrations/#migration-serializing
If I exclude all decimal variables from all of my classes, then the above command runs successfully.
So, how does one include decimals in a way that is acceptable to Django?
答案 0 :(得分:4)
根据文档,DecimalField
max_digits
和decimal_places
需要两个参数。您可以查看here。
要使用django,您需要从班级中删除elipses。你可以使用
models.DecimalField(max_digits=5, decimal_places=2)
或
models.DecimalField(default=0, max_digits=5, decimal_places=2)