обновляю запись в бд. не могу. ругается на формат. Формат строка.
def insertBdDataTime (data):
formatted_date = data.strftime('%Y-%m-%d %H:%M:%S.%f')
print(type(formatted_date))
id = 1
try:
with connection.cursor() as cursor:
cursor.execute("""SELECT * from time limit 1""")
if cursor.fetchone() is None:
insert_query = "INSERT INTO `time` (datetime_field, id) VALUES (%s, %s);"
cursor.execute(insert_query, (formatted_date, id))
connection.commit()
print('data.time в бд записана!')
else:
cursor.execute("UPDATE time SET datetime_field=? WHERE id=1", (formatted_date))
connection.commit()
print('data.time в бд обновлена!')
finally:
connection.close()
<class 'str'>
Traceback (most recent call last):
File "F:\pythonTn\main.py", line 113, in <module>
insertBdDataTime(t)
File "F:\pythonTn\database.py", line 28, in insertBdDataTime
cursor.execute("UPDATE time SET datetime_field=? WHERE id=1", (formatted_date))
File "F:\pythonTn\venv\lib\site-packages\pymysql\cursors.py", line 156, in execute
query = self.mogrify(query, args)
File "F:\pythonTn\venv\lib\site-packages\pymysql\cursors.py", line 134, in mogrify
query = query % self._escape_args(args, conn)
TypeError: not all arguments converted during string formatting