- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
尝试将 only
与 select_related
一起使用时出现此错误。
FieldError: Invalid field name(s) given in select_related: 'userinfo'. Choices are: userinfo
有点奇怪,它报告我正在尝试选择的字段为错误。这是我的查询:
users_with_schools = User.objects.select_related('userinfo').only(
"id",
"date_joined",
"userinfo__last_coordinates_id",
"userinfo__school_id"
).filter(
userinfo__school_id__isnull=False,
date_joined__gte=start_date
)
我已经能够在代码的其他地方将 select_related
与 only
一起使用,所以我不确定为什么会这样。
编辑:这是完整的回溯
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 138, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 162, in __iter__
self._fetch_all()
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
sql, params = self.as_sql()
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 367, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 48, in pre_sql_setup
self.setup_query()
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 39, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 203, in get_select
related_klass_infos = self.get_related_selections(select)
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 743, in get_related_selections
', '.join(_get_field_choices()) or '(none)',
FieldError: Invalid field name(s) given in select_related: 'userinfo'. Choices are: userinfo
最佳答案
来自documentation :
All of the cautions in the note for the
defer()
documentation apply toonly()
as well. Use it cautiously and only after exhausting your other options....
Using
only()
and omitting a field requested usingselect_related()
is an error as well.
select_related
将尝试获取 userinfo
的所有列.如上所述,尝试将列集限制为特定列将导致错误 - select_related
的组合和 only
不支持。
可能值得注意的是这些方法的注释:
The
defer()
method (and its cousin,only()
, below) are only for advanced use-cases. They provide an optimization for when you have analyzed your queries closely and understand exactly what information you need and have measured that the difference between returning the fields you need and the full set of fields for the model will be significant.
编辑:您在下面的评论中提到,在您代码的其他地方使用的以下查询似乎工作正常:
ChatUser.objects.select_related("user__userinfo").\
only( "id", "chat_id", "user__id", "user__username", "user__userinfo__id" )
我最好的猜测是你正在点击 this bug在 Django ( fixed in 1.10 ) 中。
我想最简单的验证方法是检查似乎有效的查询集生成的 SQL 查询。我的猜测是您会发现它实际上并没有一次查询所有内容,并且当您尝试访问您要求在 select_related
中获取的相关模型时还有其他查询。 .
关于python - FieldError : Invalid field name(s) given in select_related: 'userinfo' . 选择是:用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37261490/
我正在学习 java,并研究了来自 sun.com 的以下示例。 import java.io.*; import java.util.*; public class UserInfo impleme
我需要根据 URI 子集来识别用户。它具有以下模式 http://userinfo@hostname:port/path。 java.net.URI implementation 表示 URI。但是,
我正在尝试使用以下 GET 访问 Office365 Azure 租户上用户的 OpenId UserInfo 端点: GET https://login.windows.net/common/ope
如何使用 org.apache.jackrabbit.api.security.user 获取 CQ5 用户信息像java或jsp中的名称和组信息。? 最佳答案 在 JSP/Java 中,您可以将您的
我正在做一个安排本地通知并保存用户信息的应用程序。这部分没问题。 但是当应用程序关闭时,如果出现 Notification 并且用户点击,则不会调用该方法,我无法处理 userInfo。 我看到有一种
使用 Swift 语言从 xCode 获取编译错误消息:“extra argument userinfo in call”。问题是如何使用定时器中的 userInfo 数据到通知中心的参数“userI
根据ASIHTTPRequest网站: If your requests are all of the same broad type, but you want to distinguish bet
实现下一个代码时: func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLA
我调用NotificationCenter的post方法时有一个方法: func processMessage(message: CocoaMQTTMessage) { Log.d("Dest
我需要使用 userInfo 填充推送通知的字段(.title 和 .body)。我什么都试过了,但我只能输入“日期”代码块。我能怎么做?谢谢。 这是我从控制台 php 发送推送通知时的输出: OUT
我正在尝试创建我的 userinfo 命令,您可以为任何用户执行此操作,并显示服务器中的语音时间和服务器中发送的消息这是我的!!userinfo 命令 const Discord = module.r
所以我一直想弄清楚为什么 userInfo 一直没有显示我想要的数据。当我打印 userInfo 时,我得到了这个: [AnyHashable("aps"): { alert = "test
我有一个来自 UILocalNotification 的 userInfo 字典。使用隐式展开时是否有一种简单的方法来获取 String 值? if let s = userInfo?["ID"] 给
我有一个返回字典的通知,很像在 objective-c 中,但我没有得到我期望的结果。 这是发布通知的方法。它实际上是返回日期选择器的结果(日期)。 @IBAction func dateOfBirt
由于 ADFS 4.0 隐式流不返回 id_token 中的自定义声明,我尝试从 userInfo 端点获取这些声明。要获取 userinfo 端点的访问 token ,必须使用资源 urn:micr
我一直在使用身份服务器快速启动应用程序,我想添加调用userinfo端点时要返回的角色信息。 public Claim[] GetUserClaims(UserServiceProxy.Dto.U
我正在我的应用程序中使用 NSManagedObjectContextObjectsDidChangeNotification 通知,我现在已经知道如何使用它了。因为我使用了下面的代码来添加观察者..
在那段代码中,我有两个 NSLog 都表示 dict 的保留计数为 1。由于如果数组中有很多对象,计时器可能会在很长一段时间内触发,我可以保留给用户信息的字典吗?因为我猜它是自动释放的,而schedu
在当前 header 中,它声明为: @property (nonatomic, readonly, strong) NSMutableDictionary *userInfo NS_AVAILABL
我正在尝试使用 NSNotification 发送一些数据,但遇到了困难。这是我的代码: // Posting Notification NSDictionary *orientationData;
我是一名优秀的程序员,十分优秀!