1

I'm trying to create a table with 2 columns using python's mysqldb module, but I get an error, what might be wrong here?

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 Answer 1

1

Replace PRIMARY_KEY with PRIMARY KEY:

cur.execute("CREATE TABLE foreign_crew(id VARCHAR(45) PRIMARY KEY, surname VARCHAR(45))")
Sign up to request clarification or add additional context in comments.

3 Comments

thanks it worked. but i cant see the foreign_crew table when I open the database in mysql workbench. what is wrong?
Add connection.commit() after the execute. connection is the result of mysqldb.connect.
i did commit(), but still i cant see it in mysql workbench. is there a refresh button in workbench?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.