English 中文(简体)
为什么Django ORM没有发现我数据库中明确的物品?
原标题:Why is the Django ORM not finding items that are clearly in my database?

Django(价值1.1.4的改动)是任意的,没有发现属于我数据库表之一的项目。 所涉物体经理是违约者。 下面有两个例子,第一个例子说明问题的范围,第二个例子提供了具体事例。

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)

其本身就足够了。 如今,就是一个单一物体的例子,该物体在非行,但 is:

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 

出于隐私原因,我不想向大家展示我SQL问答的准确结果,但只需说,这确实是回到数据库。

这给我造成了非常奇怪的行为,有可能给Django ORM的头盔带来深.。 但我也有可能忽视一些显而易见的事情。 这怎么办?

最佳回答

Django正在寻找一个与你连接的不同数据库,或者说你已告诉Django去做一些事情。 Django没有数据。

1. 证实django与正确数据库有关:

from django import db
db.settings.DATABASES.get( default )
问题回答

Possibly the isolation level of your MySQL is REPEATEABLE READ(which is default for innodb), and the DB connection in Django shell is in a transaction earlier than the new inserting of rows(caused by manually transaction management or using of some connection-pool, etc) and still holds an expired snapshot of old rows.
Then you experienced phantom reading.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签