【发布时间】:2019-10-04 15:06:27
【问题描述】:
already_transferred = Transfer.objects.all().filter(transferred_by=request.user, account_id=id).aggregate(total=Coalesce(Sum('amount'), 0))
并且服务器给出了这个错误
function sum(text) does not exist
LINE 1: SELECT COALESCE(SUM("API_insidetransfer"."amount"), 0) AS "a...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
这是我的模型
class Transfer(models.Model):
transferred_by = models.CharField(max_length=120)
account_id = models.CharField(max_length=120)
amount = models.CharField(max_length=120, default=0)
created_on = models.DateTimeField(auto_now=True)
我该如何解决这个问题?
【问题讨论】:
-
amount是CharField? -
是的,我有其他模型,其中数量是 CharField 并且可以工作
-
当然行得通,只要您获取或存储数据,那肯定行得通。但在这里,您的目标是总结金额。你不能总结字符串。
标签: python django postgresql