column "" must appear in the GROUP BY clause or be used in an aggregate function

61 views
Skip to first unread message

徐军明

unread,
Oct 14, 2018, 9:37:49 PM10/14/18
to Django developers (Contributions to Django itself)

Django 2.1.2, Postgres 10

Model:
class Product(models.Model):
product_id = models.AutoField("产品ID", primary_key=True)
...

class SpecItem(models.Model):
spec_id = models.AutoField(primary_key=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name="product_specs", null=True)
price = models.FloatField("价格", default=0)
...

When exwcute
qs = Product.objects.filter(valid=1)
serializer = ProductSerializer(
qs.annotate(cnt=Count("product_specs"), min_price=Min("product_specs__price")).filter(cnt__gt=0)
.order_by("min_price")[offset:offset + limit],
context={"request": request},
many=True)

It says django.db.utils.ProgrammingError: column "prome_product.product_name" must appear in the GROUP BY clause or be used in an aggregate function


Can anyone help me?

Kotha bondhu Mithun

unread,
Oct 15, 2018, 1:56:23 PM10/15/18
to django-d...@googlegroups.com
sorry friend....iam also try it


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d020a431-78db-41b0-809d-a0283a041f7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Johnson

unread,
Oct 15, 2018, 2:46:53 PM10/15/18
to django-d...@googlegroups.com
This mailing list is for the development of Django itself, not for support. Use the django-users mailing list for that, or IRC #django on freenode, or a site like Stack Overflow.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d020a431-78db-41b0-809d-a0283a041f7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam
Reply all
Reply to author
Forward
0 new messages