python - 注释“...”与模型上的字段冲突
问题描述
我想写相当于
select coalesce(product_id, -1) as product_id from my_table
在django。然而,尝试
MyTable.objects.values(product_id=Coalesce('product_id', -1))
给我错误:The annotation 'product_id' conflicts with a field on the model.
这迫使我使用不同的名称,并在 python 中重命名生成的 dicts,这比在数据库中执行要慢得多。
有没有办法告诉django“我知道我在做什么,继续”???
解决方案
尝试不同的名称而不是您的模型属性,
MyTable.objects.values(change_product_id=Coalesce('product_id', -1))
推荐阅读
- python - 仅从 pandas 数据框列中的 json 格式获取特定键值
- react-native - 无需电话号码即可与 Twilio Flex 和 React Native 聊天
- c# - HTTP 未解析的 ping - TCP 服务器
- firebase - 从 firebase 存储读取并使用 firebase 函数写入 firestore
- python - 将嵌套字典转换为数据框
- linux - find -perm 查找不存在的文件(或其他文件)
- ajax - 我跟着一个视频教程。我正在尝试使用 ajax 和 jquery 在我的 django 项目的主页上呈现微调器
- c# - 蛇盒属性的类属性
- docker - 使用策略“”拉取图像失败:图像拉取失败:后退拉取图像“
" - google-apps-script - 使用 Google Ads 脚本在电子表格列中搜索值