Django (version 1.1.4 for what it’s worth) is arbitrarily not finding items that are in one of my database tables. The objects manager in question is the default one. Two examples follow, the first showing the scope of the problem, the second providing a particular instance of it.
Django:
In [5]: LocalStore.objects.all().count()
Out[5]: 1466
MySQL:
mysql> select count(*) from stores_localstore;
+----------+
| count(*) |
+----------+
| 1553 |
+----------+
1 row in set (0.00 sec)
Strange enough by itself. Now here’s an example of a single object that’s in the DB but isn’t showing up:
Django:
In [37]: LocalStore.objects.filter(id=474361)
Out[37]: []
In [39]: print LocalStore.objects.filter(id=474361).query
SELECT `stores_localstore`.`id`, `stores_localstore`.`cust_id`,
`stores_localstore`.`name`, `stores_localstore`.`lat`, `stores_localstore`.`lng`,
`stores_localstore`.`addr1`, `stores_localstore`.`addr2`, `stores_localstore`.`city`,
`stores_localstore`.`email`, `stores_localstore`.`fax`, `stores_localstore`.`phone`,
`stores_localstore`.`state`, `stores_localstore`.`url`, `stores_localstore`.`zip` FROM
`stores_localstore` WHERE `stores_localstore`.`id` = 474361
For privacy reasons, I don’t want to show you the exact result of the MySQL query, but it should suffice to say that it does return a database row.
This strikes me as very strange behavior and potentially a bug deep in the bowels of the Django ORM. But it’s also possible that I’m overlooking something obvious. What could that be?
Django is either looking at a different database than you’re connected to, or you have told django to cache somehow. Django does not ‘lose’ data.
Validate that django is connected to the right database: