Django reported an error: 'key' ID 'not found in' xxx '. Choices are: xxx'

Mr. young 2021-01-21 23:36:48
django reported error key id


Environmental Science :

Python 3.6
Django 2.2

problem :

I am here Django Of admin.py In the file for a Models Configured with fields Field , Cause to view a specific data , Tips :Django "Key 'id' not found in 'xxx'. Choices are: xxx"

Cause error code :

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ['id','name']
fields = ['id','name'] # This line of code causes an error 

reason :

Because fields id Auto increment of settings ID key , In the database, the corresponding is AUTO_INCREMENT, So this field is not allowed to be edited , and fields The configuration setting is to display the edit fields , This leads to conflict , That's why it's wrong .

terms of settlement :

Just change the code to the following

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ['id','name']
fields = ['name'] # Remove this line of code id Field 
This article was first published in BigYoung Way station
版权声明
本文为[Mr. young]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210121224050462F.html

  1. 前后端分离有什么了不起,手把手教你用Python爬下来!
  2. 在 Azure 上执行一些简单的 python 工作
  3. 推荐 :利用Python的混合集成机器学习(附链接)
  4. Cunning or orthodox Kung Fu? The most complete usage of Python derivation
  5. It's estimated that 80% of pandas people have to hang up!
  6. What's so great about the separation of front and rear ends? Hand in hand teach you to climb down with Python!
  7. Doing some simple Python work on azure
  8. Recommendation: hybrid integrated machine learning using python (link attached)
  9. Learning PPO algorithm programming from scratch (Python version)
  10. Python OpenCV 图片模糊操作 blur 与 medianBlur
  11. Python OpenCV image blur operation blur and mediablur
  12. 成功解决cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: err
  13. Cv2.error solved successfully: opencv (4.1.2) C:: (projects / opencv Python / opencv modules / imgproc / SRC)\ color.cpp:182 : err
  14. Python 中使用 virtualenv 管理虚拟环境
  15. Using virtualenv to manage virtual environment in Python
  16. 如何使用Python执行系统命令?Python学习教程!
  17. How to use Python to execute system commands? Python tutorial!
  18. 快速掌握Python中的循环技术
  19. Quickly grasp the loop technology in Python
  20. Python主流Web框架之Tornado
  21. appium+python自动化63-使用Uiautomator2报错问题解决
  22. Tornado: the mainstream Python Web Framework
  23. Appium + Python automation 63 - using uiautomator2 to solve the problem of error reporting
  24. 爬虫+django,打造个性化API接口
  25. Crawler + Django to create personalized API interface
  26. 爬虫+django,打造个性化API接口
  27. Crawler + Django to create personalized API interface
  28. C、C++、Java、PHP、Python主要应用在哪里方面?
  29. C. Where are the main applications of C + +, Java, PHP and python?
  30. Python 无限级分类树状结构生成算法 「实用代码」
  31. Python infinite classification tree structure generation algorithm "practical code"
  32. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
  33. [azure storage service] Python module( azure.cosmosdb.table )Direct operation example of storage account table
  34. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
  35. [azure storage service] Python module( azure.cosmosdb.table )Direct operation example of storage account table
  36. openpose c++ 配置教程 + python api
  37. Openpose C + + configuration tutorial + Python API
  38. PYTHON爬虫实战_垃圾佬闲鱼爬虫转转爬虫数据整合自用二手急速响应捡垃圾平台_3(附源码持续更新)
  39. 使用python javaSerializationTools模块拼接生成 8u20 Gadget
  40. 萌新入门之python基础语法
  41. python中hmac模块的使用
  42. Python crawler_ Garbage man idle fish crawler turn crawler data integration self use second hand rapid response garbage collection platform_ 3 (with continuous source update)
  43. Using Python javaserialization tools module to generate 8u20 gadget
  44. The basic syntax of Python
  45. The use of HMAC module in Python
  46. 攻防世界web进阶区Web_python_block_chain详解
  47. Attack and defense world web advanced zone Web_ python_ block_ Details of chain
  48. pandas DataFrame的新增行列,修改、删除、筛选、判断元素以及转置操作
  49. Add rows and columns, modify, delete, filter, judge elements and transpose operations in pandas dataframe
  50. pandas DataFrame的新增行列,修改、删除、筛选、判断元素以及转置操作
  51. Add rows and columns, modify, delete, filter, judge elements and transpose operations in pandas dataframe
  52. 虚言妙诀终虚见,面试躬行是致知,Python技术面试策略与技巧实战记录
  53. The interview practice is knowledge, python technology interview strategy and skills of the actual record
  54. 用tqdm和rich为固定路径和目标的python算法代码实现进度条
  55. Using tqdm and rich as the fixed path and target of Python algorithm code to realize the progress bar
  56. 我来记笔记啦-Django开发流程与配置
  57. Let me take notes - Django development process and configuration
  58. python数据类型的强制转换
  59. Django报错:'Key 'id' not found in 'xxx'. Choices are: xxx'
  60. Python400集大型视频,从正确的方向出发学习,全套完整送给大家