我正在尝试添加当前时间戳i.n. qazxsw poi进入我的mariadb(SQL)表,但在终端中运行脚本给了我一个错误。
这个脚本的问题部分是:
now()
(数据4和数据6是在此之前在我的脚本中生成的变量。)
我得到的错误是:cursor.execute("INSERT INTO outdoorsensorstable
(time, col2, col3, col4, col5, col6, col7)
VALUES (%s, %s, %s, %s, %s, %s, %s)",
(now(), '', '', data4, '', data6, ''))
然后我尝试通过将TypeError: 'datetime.datetime' object is not callable
放入VALUES段来解决这个问题,如下所示:
now()
但是我在运行脚本时遇到另一个错误:
cursor.execute("INSERT INTO outdoorsensorstable (time, col2, col3, col4, col5, col6, col7) VALUES (now(), %s, %s, %s, %s, %s, %s)", ('', '', '', data4, '', data6, ''))
任何想法为什么以及如何解决这个问题?
你的第二次努力几乎是正确的;只是不传递mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement
的任何参数,因为它不是一个参数,因为它是硬编码的:
NOW()