Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Hi,

I'm learning to work with Python with MySQL databases via the PyMySQL add-on. If I use the code below, I get an error:

pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1) .

Can someone please advise what to do with it? Thank you

Python piece of code



now = datetime.today()
log([0, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', 'root', now])


Method



# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5]))

cur.execute(sql)
con.commit()


Error



Traceback (most recent call last):
File "/var/xyz/ht.py", line 198, in
log([1, 'xyz_ht', 'run', 'xyz_ht', 'ht.py', now])
File "/var/xyz/ht.py", line 70, in log
cur.execute(sql)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 856, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1057, in _read_query_result
result.read()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1340, in read
first_packet = self.connection._read_packet()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 1014, in _read_packet
packet.check_error()
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/usr/lib/python3.4/site-packages/PyMySQL-0.7.11-py3.4.egg/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1136, "Column count doesn't match value count at row 1")


REPLY


Hi,

the error Column count doesn't match value value at row in this case means that the field index does not match = log[6] is missing here.

So right like this:

# logovani
def log(log):
con = mysql.connect(**config)
with con:
cur = con.cursor()
sql = str("INSERT INTO logs (`log_bond`, `log_table`, `log_operation`, `log_data`, `log_subdata`, `log_user`, `log_date`) \
VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')" \
.format(log[0], log[1], log[2], log[3], log[4], log[5], log[6]))

cur.execute(sql)
con.commit()

Související obsah

programovani

python

mysql

databaze

Komentáře

Vaše reakce na Python - pymysql.err.InternalError: (1136, Column count doesn't match value count at row 1)

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.