Django 类型错误 : argument must be int or float when trying to access model

标签 django django-models

每当我尝试访问我的模型之一时,我都会遇到一个非常奇怪的错误。所有其他模型都可以正常工作。

这是我的模型的样子:

class Hop(models.Model):
    name = models.CharField(max_length=100, null=True, blank=True)
    aa = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True, default = 10)
    b = models.DecimalField(max_digits=15, decimal_places=2, null=True, blank=True)
    type = models.CharField(max_length=100, null=True, blank=True)
    description = models.CharField(max_length=600, null=True, blank=True)
    user_created = models.BooleanField(default=True)

    def __unicode__(self):
        return self.name

当我运行 Hop.objects.all() 时,出现以下错误。以前从未见过这个。
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\models\query.py", line 250, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\models\query.py", line 274, in __iter__
    self._fetch_all()
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\models\query.py", line 1242, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\models\query.py", line 72, in __iter__
    for row in compiler.results_iter(results):
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\models\sql\compiler.py", line 1044, in apply_converters
    value = converter(value, expression, connection)
  File "C:\Users\corym\Documents\Projects\mybrewlab vue\Backend\mybrewlabapi\env3\lib\site-packages\django\db\backends\sqlite3\operations.py", line 285, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
TypeError: argument must be int or float

最佳答案

只需删除该应用程序的迁移文件夹(接受 __init__.py)中的所有文件,并删除 db.sqlite3 .然后再次进行迁移,并在迁移后再次创建 super 用户。
它对我有用。

关于Django 类型错误 : argument must be int or float when trying to access model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57235141/

相关文章:

python - Django - 唯一约束失败

python - django ,模型列表到字符串列表

python - 如何像 Django 存储用户一样在 Django 的后端 session 中存储对象

database - 如何让多个django网站共享一个用户数据库进行身份验证?

Django 查询集过滤器空 JSONField

python - 我必须使用 AWS RDS 的副本,我应该如何设置 django 设置?

python - Django 找不到我的模板

django - 使用直通模型了解 Django 中的多对多字段

python - Django 1.7b4中继承BaseUser错误

python - Django 中的模型历史