使用mysqldb模块创建表时出错

时间:2013-08-31 19:54:04

标签: python mysql database python-2.7 mysql-python

我正在尝试使用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")

1 个答案:

答案 0 :(得分:1)

PRIMARY_KEY替换为PRIMARY KEY

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