gpt4 book ai didi

python - 使用 mysqldb 模块创建表时出错

转载 作者:行者123 更新时间:2023-11-29 00:26:46 25 4
gpt4 key购买 nike

我正在尝试使用 python 的 mysqldb 模块创建一个包含 2 列的表,但出现错误,这里可能出了什么问题?

cur.execute("CREATE TABLE foreign_crew(id VARCHAR(45) PRIMARY_KEY, surname VARCHAR(45))")

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 202, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
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 ') PRIMARY_KEY, surname VARCHAR(45))' at line 1")

最佳答案

PRIMARY_KEY 替换为 PRIMARY KEY:

cur.execute("CREATE TABLE foreign_crew(id VARCHAR(45) PRIMARY KEY, surname VARCHAR(45))")

关于python - 使用 mysqldb 模块创建表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com