4
我對這個查詢錯誤而執行查詢
query = "select count(*) from pgns_game where raw_moves = %s"
params = ('a',)
total_rows = self.model.objects.raw(query, params)
得到一個錯誤信息,它說
InvalidQuery('Raw query must include the primary key')
我清楚地失去了一些東西,但我不知道是什麼。有任何想法嗎?
在這裏說的文檔(http://docs.djangoproject.com/en/1.2/topics/db/sql/#deferring-model-fields):「只有一個領域,你不能離開 - 主鍵字段Django使用主鍵來標識模型實例,因此它必須始終包含在原始查詢中,如果忘記包含主鍵,則會引發InvalidQuery異常。 – bernie 2010-05-26 03:19:37