我正在使用 MySQLdb 并遇到以下问题:
STMT="""INSERT INTO test_table VALUES (%s, %s, %s, %s, %s)"""
rows=[('Wed Apr 14 14:00:00 2010', 23L, -2.3, 4.41, 0.83923)]
conn.cursor().executemay(STMT, rows)
结果:
Traceback (most recent call last):
File "run.py", line 122, in <module>
File "C:\Python25\lib\site-packages\mysql_python-1.2.2.0002-py2.5-win32.egg\MySQLdb\cursors.py", line 276, in _do_query
db.query(q)
_mysql_exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1")
有什么提示吗?
最佳答案
尝试显式写入 INSERT 中的所有列:
STMT = 'INSERT INTO test_table (col1, col2, col3, col4, col5) VALUES (%s, %s, %s, %s, %s)'
关于python - 执行很多问题,MySQLdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3811431/