1054 Unknown column 'xxxxxx.id' in 'field list'

本文解决了一个常见的Django应用问题,当在视图中筛选数据库表数据时,由于表未设置主键而引发的“1054 Unknown column '表名.id' in 'fieldlist'”错误。通过在数据库中使用SQL语句添加主键,成功解决了此问题。
部署运行你感兴趣的模型镜像

1054 Unknown column ‘xxxxxx.id’ in ‘field list’@数据库的表未设置主键报错

问题背景:

在pycharm里,使用Django做API,在views里对项目连接的数据库的表里的数据做筛选时,总是报出“1054 Unknown column ‘xxxxx(数据库表名).id’ in ‘field list’”
在网上查了许多相关信息,要么告知字段写错,要么告知多了空格,也许那些也是他们遇到错误的原因,我遇到的这个问题,根本原因在于:
所连接的数据库的数据表,表没有设置“主键”,导致报错;

如下为我遇见的报错具体内容:

django.db.utils.OperationalError: (1054, “Unknown column ‘alarm_description.id’ in ‘field list’”)
[07/Aug/2019 16:50:51] “GET /most_failure_list/ HTTP/1.1” 500 159621

解决办法

在数据库的操作页面里,console页面,通过mysql的操作指令:
alter table app_test4.alarm_description add primary key(alarm_type_id)
将数据表“app_test4.alarm_description”的列“alarm_type_id”设置为主键;
即可解决;
设置主键后,该字段的右上角会有一个金色的小钥匙;代表该列是主键;
然后该问题即可解决;
在这里插入图片描述设置主键前,不带金钥匙,设置后带金钥匙;

您可能感兴趣的与本文相关的镜像

Langchain-Chatchat

Langchain-Chatchat

AI应用
Langchain

Langchain-Chatchat 是一个基于 ChatGLM 等大语言模型和 Langchain 应用框架实现的开源项目,旨在构建一个可以离线部署的本地知识库问答系统。它通过检索增强生成 (RAG) 的方法,让用户能够以自然语言与本地文件、数据库或搜索引擎进行交互,并支持多种大模型和向量数据库的集成,以及提供 WebUI 和 API 服务

[2025-08-08 10:18:08.008] [org.springframework.boot.StartupInfoLogger] - [logStarting,55] [main] [55] [INFO ] Starting NativePayApplication v0.0.1-SNAPSHOT using Java 1.8.0_152 on WIN-1L04BDEVRGR with PID 3124 (D:\扫码支付前置服务\NativePay-0.0.1-SNAPSHOT.jar started by Administrator in D:\扫码支付前置服务) [2025-08-08 10:18:08.008] [org.springframework.boot.StartupInfoLogger] - [logStarting,56] [main] [56] [DEBUG] Running with Spring Boot v2.4.4, Spring v5.3.5 [2025-08-08 10:18:08.008] [org.springframework.boot.SpringApplication] - [logStartupProfileInfo,662] [main] [662] [INFO ] No active profile set, falling back to default profiles: default [2025-08-08 10:18:09.009] [org.mybatis.logging.Logger] - [warn,44] [main] [44] [WARN ] No MyBatis mapper was found in '[com.example.NativePay]' package. Please check your configuration. [2025-08-08 10:18:09.009] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] - [initialize,108] [main] [108] [INFO ] Tomcat initialized with port(s): 8192 (http) [2025-08-08 10:18:09.009] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Initializing ProtocolHandler ["http-nio-8192"] [2025-08-08 10:18:09.009] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Starting service [Tomcat] [2025-08-08 10:18:09.009] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Starting Servlet engine: [Apache Tomcat/9.0.44] [2025-08-08 10:18:10.010] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Initializing Spring embedded WebApplicationContext [2025-08-08 10:18:10.010] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] - [prepareWebApplicationContext,289] [main] [289] [INFO ] Root WebApplicationContext: initialization completed in 1484 ms [2025-08-08 10:18:10.010] [org.springframework.scheduling.concurrent.ExecutorConfigurationSupport] - [initialize,181] [main] [181] [INFO ] Initializing ExecutorService 'applicationTaskExecutor' [2025-08-08 10:18:10.010] [com.baomidou.mybatisplus.core.metadata.TableInfoHelper] - [initTableFields,296] [main] [296] [WARN ] Warn: Could not find @TableId in Class: com.example.NativePay.domian.ExecBusinessreCord. [2025-08-08 10:18:11.011] [com.baomidou.mybatisplus.core.metadata.TableInfoHelper] - [initTableFields,296] [main] [296] [WARN ] Warn: Could not find @TableId in Class: com.example.NativePay.domian.PayResultRecord. [2025-08-08 10:18:11.011] [com.baomidou.mybatisplus.core.metadata.TableInfoHelper] - [initTableFields,296] [main] [296] [WARN ] Warn: Could not find @TableId in Class: com.example.NativePay.domian.RefundRecord. [2025-08-08 10:18:11.011] [com.baomidou.mybatisplus.core.metadata.TableInfoHelper] - [initTableFields,296] [main] [296] [WARN ] Warn: Could not find @TableId in Class: com.example.NativePay.domian.RefundResult. [2025-08-08 10:18:11.011] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Starting ProtocolHandler ["http-nio-8192"] [2025-08-08 10:18:11.011] [org.springframework.context.support.AbstractApplicationContext] - [refresh,591] [main] [591] [WARN ] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server [2025-08-08 10:18:11.011] [org.springframework.scheduling.concurrent.ExecutorConfigurationSupport] - [shutdown,218] [main] [218] [INFO ] Shutting down ExecutorService 'applicationTaskExecutor' [2025-08-08 10:18:11.011] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Pausing ProtocolHandler ["http-nio-8192"] [2025-08-08 10:18:11.011] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Stopping service [Tomcat] [2025-08-08 10:18:11.011] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Stopping ProtocolHandler ["http-nio-8192"] [2025-08-08 10:18:11.011] [org.apache.juli.logging.DirectJDKLog] - [log,173] [main] [173] [INFO ] Destroying ProtocolHandler ["http-nio-8192"] [2025-08-08 10:18:11.011] [org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener] - [logMessage,136] [main] [136] [INFO ] Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 什么原因导致的jar包没有启动成功
最新发布
08-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值