簡體   English   中英

Python MySQL錯誤1064插入日期時間字符串

[英]Python MySQL Error 1064 inserting datetime string

我有以下python代碼:

now = time.strftime('%Y-%m-%d %H:%M:%S')
#now = datetime.datetime.now()
query = """INSERT INTO bandwidth_by_second (current_time, down, up)  VALUES (%s, %s, %s)"""
data = (now, 1.0, 2.0)
cursor.execute(query, data)

我對此表的架構是:

  • current_time-數據時間
  • 下-雙
  • 向上-加倍

運行此命令時,出現以下錯誤:

_mysql_exceptions.ProgrammingError:(1064,“您的SQL語法有錯誤;請查看與您的MySQL服務器版本相對應的手冊,以獲取正確的語法以在'current_time,down,up附近使用)VALUES('2014-10-27 18 :29:32',1,1)'在第1行“)

我以為我將日期時間的格式設置為錯誤,但是這篇文章提出了其他建議。

到底他媽發生了什么?

在引號中使用“%s”。 然后它將起作用:)

它與數據庫表中的列名有關。 我將current_time更改為currenttime ,並且開始工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM