回答

收藏

MySQL语法错误“在'desc'附近使用的高度语法”。

技术问答 技术问答 67 人阅读 | 0 人回复 | 2023-09-13

我正在使用Python并使用MySQLdb模块。我的连接正常(我可以成功运行其他查询)
' U0 N! }, \. K% c$ @9 \c.execute("ALTER TABLE results ADD COLUMN desc TEXT")2 F9 y, {& V( e) Q, D8 X
Traceback (most recent call last):" O0 w0 W& q9 W& y4 e* I" a
  File "", line 1, in
$ D+ f" V* ?+ i; W: @5 L: l/ D  File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute9 M+ `# h, d' T& L% W
    self.errorhandler(self, exc, value)
6 I& s; E' ]6 w9 X  File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35,9 D" Q9 v) G- `3 R
    in defaulterrorhandler: u- {+ c5 k. c. @3 l
    raise errorclass, errorvalue' Q1 X2 \# u# q; a
我收到以下错误:2 b3 f) {' G. K0 w
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
& G' L, S, `* n$ w5 [  i: I) Qsyntax; check the manual that corresponds to your MySQL server version for the; h* \3 F4 o5 L; r( |
right syntax to use near 'desc TEXT' at line 1")( Q6 ~0 y5 q7 V4 U3 K/ [2 z
我以前也遇到过类似的麻烦;MySQLdb的语法错误消息 非常 难以描述。
' s  g  c+ [8 _! E* P2 x如何解决?
7 i/ B7 s, M/ ~- v; y8 ?1 E                # F8 [4 h! @' |# h3 D
解决方案:8 m" m1 n  m3 L" G
                + F6 U, i4 a& }, ^6 `  O

" |7 W- a$ X  R$ [: }9 a
  W) ^1 {& W# y5 ~                我相信desc是保留的。在ORDER BY子句中使用. e, g0 u, O) s
如果对它放回去,您也许可以摆脱使用它的困扰,但是我认为将名称更改为非保留字会更好。
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则