gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:51:23 25 4
gpt4 key购买 nike

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

这是我的模型的样子:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com