Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 18, 2011 20:24:45

mack t.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

len(qs.all()) != qs.count()


>>> p=EtilizeProduct.objects.all().using('etilize')
>>> p.productdescription_set.all()

>>> p.productdescription_set.count()
4

Does anybody have any idea why count() returns 4, but all() returns an empty
list? I'm not using any custom routers.

>>> str(p.productdescription_set.all().query)
'SELECT "productdescriptions"."id", "productdescriptions"."productid",
"productdescriptions"."description", "productdescriptions"."isdefault",
"productdescriptions"."type", "productdescriptions"."
localeid" FROM "productdescriptions" WHERE "productdescriptions"."productid"
= 1015433472 '

When I try to enter that command into a dbshell, I get a syntax error. If I
remove the quotation marks, I'll get the 4 results:

$ ./manage.py dbshell --database etilize
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 269
Server version: 5.1.49-1ubuntu8.1 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.

mysql> SELECT "productdescriptions"."id", "productdescriptions"."productid",
"productdescriptions"."description", "productdescriptions"."isdefault",
"productdescriptions"."type", "productdescriptions"."localeid" FROM
"productdescriptions" WHERE "productdescriptions"."productid" = 1011081147;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near '."id", "productdescriptions"."productid",
"productdescriptions"."description", "' at line 1
mysql> SELECT "productdescriptions".* FROM "productdescriptions" WHERE
"productdescriptions"."productid" = 1011081147;ERROR 1064 (42000): You have
an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '.* FROM
"productdescriptions" WHERE "productdescriptions"."productid" = 10110811' at
line 1
mysql> SELECT productdescriptions.* FROM productdescriptions WHERE
productdescriptions.productid = 1011081147;
+------------+----------------------------------------------------------------------------------------------------------------------------+-----------+------+----------+
| productid | description
| isdefault |
type | localeid |
+------------+----------------------------------------------------------------------------------------------------------------------------+-----------+------+----------+
| 1011081147 | Symantec (10888497) Software Licensing
| 0 |
0 | 1 |
| 1011081147 | Symantec VERITAS Storage Foundation v.5.0 Enterprise HA for
DB2 Crossgrade License - Government - 1 Server - Price Level S | 1 |
1 | 1 |
| 1011081147 | Symantec VERITAS Storage Foundation v.5.0 Enterprise HA for
DB2 | 0 |
2 | 1 |
| 1011081147 | Crossgrade License - Government - 1 Server - Price Level S
| 0 |
3 | 1 |
+------------+----------------------------------------------------------------------------------------------------------------------------+-----------+------+----------+
4 rows in set (0.12 sec)

mysql> Bye

What could be causing this?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 19, 2011 12:05:41

Martin P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

len(qs.all()) != qs.count()


I would say the problem is in your model. Notice in the beginning of the SQL
there is "productdescriptions"."id" yet there is no such field in database.
Just specify
primary_key=True<http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.primary_key>on
one of your fields.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support