python3连接数据库出现1054, "Unknown column 'version' in 'field list'"错误

本文分享了在使用Python连接MySQL数据库时遇到的1054错误:Unknown column 'version' in 'field list'的解决过程。错误原因为SQL语句中遗漏了函数括号,正确的写法应为cursor.execute('select version()')而非cursor.execute('select version')。此错误提醒我们在编写SQL语句时需仔细检查语法细节。

今天连接mysql数据库时出现1054, "Unknown column ‘version’ in ‘field list’"这个出现,一开始感觉自己写的代码没错,所以就上网搜了一下,结果发现报这个错误好像都是因为写的sql语句有错误,又重新检查了一遍,果然是因为sql语句的错误。cursor.execute(“select version”)这个和cursor.execute(“select version()”)就是因为少了个()就报错了,自己很粗心(捂脸)。

"C:\Program Files\Python39\python.exe" "D:\AEB Management\9.py\MySQL_JIRA_Normative_Health\main.py" 2025-12-06 13:18:10,508 - INFO - 目标表列名: ['summary', 'issue key', 'issue id', 'parent id', 'issue type', 'status', 'project key', 'project name', 'project type', 'project lead', 'project description', 'project url', 'priority', 'resolution', 'assignee', 'reporter', 'creator', 'created', 'updated', 'last viewed', 'resolved', 'affects version/s', 'fix version/s', 'component/s', 'due date', 'labels', 'description', 'environment', 'watchers', 'log work', 'security level', 'total', 'custom field (control no)', 'custom field (custom_1)', 'custom field (custom_2)', 'custom field (date of first response)', 'custom field (experience owner)', 'custom field (fixed in release)', 'custom field (found by)', 'custom field (found in hw version)', 'custom field (found in mech version)', 'custom field (found in svn version)', 'custom field (found in sw version)', 'custom field (kochi issue type)', 'custom field (kochi issue type transition)', 'custom field (last comment)', 'custom field (matter)', 'custom field (project number)', 'custom field (project number p)', 'custom field (rank)', 'custom field (realisation planned)', 'custom field (report number)', 'custom field (report type)', 'custom field (reported by)', 'custom field (risk)', 'custom field (start date)', 'custom field (team)', 'comment', 'involvement of bsw', 'date', 'projectnum', 'bsw self test', 'bsw issue', 'stack bsw analyzed', 'stack bsw unanalyzed', 'stack total', 'bsw involve', 'bsw involve unclosed', 'horizontalexpansion count', 'horizontalexpansion pn', 'horizontalexpansion unfinished', 'horizontalexpansion delay', 'bsw analysis conclusions', 'stack classification', 'bsw reason classification', 'bsw staff list', 'found by classification', 'high priority unanalyzed', 'update_over_15', 'update_over_7', 'responsible', 'email', 'bsw analyzed', 'bsw unanalyzed', 'bsw deal time', 'bsw team', 'jira link', 'stack classification completion', 'weekly', 'py time'] 2025-12-06 13:18:10,508 - INFO - 开始计算项目聚合值... 2025-12-06 13:18:10,530 - ERROR - 数据库连接失败: (pymysql.err.OperationalError) (1054, "Unknown column 'BSW Involved' in 'field list'") [SQL: SELECT `Project key`, SUM(COALESCE(`BSW Involved`, 0)) AS total_bsw_involved, SUM(COALESCE(`Stack BSW Analyzed`, 0)) AS total_bsw_analyzed, SUM(COALESCE(`Stack BSW Unanalyzed`, 0)) AS total_bsw_unanalyzed FROM jira_task_bsw_deal GROUP BY `Project key` ] (Background on this error at: https://sqlalche.me/e/20/e3q8) 2025-12-06 13:18:10,532 - ERROR - 数据库连接失败: (pymysql.err.OperationalError) (1054, "Unknown column 'BSW Involved' in 'field list'") [SQL: SELECT `Project key`, SUM(COALESCE(`BSW Involved`, 0)) AS total_bsw_involved, SUM(COALESCE(`Stack BSW Analyzed`, 0)) AS total_bsw_analyzed, SUM(COALESCE(`Stack BSW Unanalyzed`, 0)) AS total_bsw_unanalyzed FROM jira_task_bsw_deal GROUP BY `Project key` ] (Background on this error at: https://sqlalche.me/e/20/e3q8) 2025-12-06 13:18:10,534 - ERROR - ETL流程执行失败 Traceback (most recent call last): File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\default.py", line 951, in do_execute cursor.execute(statement, parameters) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\cursors.py", line 153, in execute result = self._query(query) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\cursors.py", line 322, in _query conn.query(q) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 575, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 826, in _read_query_result result.read() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 1203, in read first_packet = self.connection._read_packet() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 782, in _read_packet packet.raise_for_error() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\protocol.py", line 219, in raise_for_error err.raise_mysql_exception(self._data) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\err.py", line 150, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.OperationalError: (1054, "Unknown column 'BSW Involved' in 'field list'") The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\AEB Management\9.py\MySQL_JIRA_Normative_Health\main.py", line 167, in main process_data( File "D:\AEB Management\9.py\MySQL_JIRA_Normative_Health\main.py", line 92, in process_data df_agg = pd.read_sql_query(agg_query, con=source_conn) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pandas\io\sql.py", line 528, in read_sql_query return pandas_sql.read_query( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pandas\io\sql.py", line 1848, in read_query result = self.execute(sql, params) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pandas\io\sql.py", line 1671, in execute return self.con.exec_driver_sql(sql, *args) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 1779, in exec_driver_sql ret = self._execute_context( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 1846, in _execute_context return self._exec_single_context( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 1986, in _exec_single_context self._handle_dbapi_exception( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 2355, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\sqlalchemy\engine\default.py", line 951, in do_execute cursor.execute(statement, parameters) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\cursors.py", line 153, in execute result = self._query(query) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\cursors.py", line 322, in _query conn.query(q) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 575, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 826, in _read_query_result result.read() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 1203, in read first_packet = self.connection._read_packet() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\connections.py", line 782, in _read_packet packet.raise_for_error() File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\protocol.py", line 219, in raise_for_error err.raise_mysql_exception(self._data) File "C:\Users\dong004\AppData\Roaming\Python\Python39\site-packages\pymysql\err.py", line 150, in raise_mysql_exception raise errorclass(errno, errval) sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1054, "Unknown column 'BSW Involved' in 'field list'") [SQL: SELECT `Project key`, SUM(COALESCE(`BSW Involved`, 0)) AS total_bsw_involved, SUM(COALESCE(`Stack BSW Analyzed`, 0)) AS total_bsw_analyzed, SUM(COALESCE(`Stack BSW Unanalyzed`, 0)) AS total_bsw_unanalyzed FROM jira_task_bsw_deal GROUP BY `Project key` ] (Background on this error at: https://sqlalche.me/e/20/e3q8) 进程已结束,退出代码为 0
最新发布
12-07
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值