因此,我试图在 python 中创建一个 sql 语句,将具有特定名称的列添加到表中,但我得到了您在标题中看到的错误。
我目前正在使用此代码。
columnname = 'note'
cur.execute("ALTER TABLE my_table_name ADD COLUMN %s MEDIUMTEXT", (columnname,))
这应该在 my_table_name 中创建一个名为 note 的列,但它给了我这个错误:MySQLdb._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 ''note' MEDIUMTEXT' at line 1")
希望有人能指出我做错了什么?谢谢。
编辑:我知道我应该使用普通的字符串插值。但是如果其他列已经在存储数据,我想继续添加列,例如 column1 然后 column2 然后 column3 。