2
我有一個被標記獨特的模型上現場:的get()節選MultipleObjectsReturned一個字段標有獨特的
uid = models.CharField(max_length=255, blank=False, null=False, unique=True)
我試圖使用get()來獲得一個配置文件應該符合這個UID :
UserProfile.objects.get(uid=fr_uid)
的問題是,此行引起了MultipleObjectsReturned
例外對一些用戶來說,即使那場被標記獨特:
Line: return self.get_query_set().get(*args, **kwargs)
Local variables:
clone [<Profile: John Smith>, <Profile: John Smith>]
num 2
如果我得到一個shell相同的配置文件,我只得到一回:
Profile.objects.get(uid='abc1234')
<Profile: John Smith>
現在我明白了,我也許應該無論如何處理一個MultipleObjectsReturned
例外,但我不明白爲什麼我會永遠得到多個對象在標有唯一性的字段上返回。