我正在使用Python並使用MySQLdb模塊。我有一個有效的連接(我可以成功運行其他查詢)MySQL語法錯誤「在desc附近使用正確的語法
c.execute("ALTER TABLE results ADD COLUMN desc TEXT")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35,
in defaulterrorhandler
raise errorclass, errorvalue
,我發現了以下錯誤:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near 'desc TEXT' at line 1")
我以前也有類似的麻煩; MySQLdb的語法錯誤信息是,非常具有說明性,。
這怎麼解決?
第1步。比較你的語法:http://dev.mysql.com/doc/refman/5.1/en/alter-table.html。錯誤消息不應該是描述性的。 –
我認爲*錯誤消息來自SQL引擎本身,而不是MySQLdb。 – mtrw