0

Hi can anybody check my syntax error here? I tried to create a table in python's mysql.connector, but keep getting the same error no matter whatI changed.

CREATE TABLE IF NOT EXISTS #TTC (
        City varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
        Address varchar(255), 
        PersonID int,
        LastNameee varchar(255),
        LaaaaaastName varchar(255),
        LasssssstName varchar(255),
);

I keep getting error message from running this piece of code in a larger program,

MySQLInterfaceError                       Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    486                 query = query.encode('utf-8')
--> 487             self._cmysql.query(query,
    488                                raw=raw, buffered=buffered,

MySQLInterfaceError: 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 'varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
' at line 2

During handling of the above exception, another exception occurred:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-29-9ae0d306f12e> in <module>
     13     print(create_table)
     14 
---> 15     cursor.execute(create_table)

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/cursor_cext.py in execute(self, operation, params, multi)
    262 
    263         try:
--> 264             result = self._cnx.cmd_query(stmt, raw=self._raw,
    265                                          buffered=self._buffered,
    266                                          raw_as_string=self._raw_as_string)

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mysql/connector/connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    489                                raw_as_string=raw_as_string)
    490         except MySQLInterfaceError as exc:
--> 491             raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
    492                                              sqlstate=exc.sqlstate)
    493         except AttributeError:

ProgrammingError: 1064 (42000): 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 'varchar(255),
        LastName varchar(255),
        FirstName varchar(255), 
' at line 2

3
  • 1
    The last column, it shouldn't end in a , Commented Jul 8, 2020 at 5:27
  • Hi, I changed that, but the error still pops up. Commented Jul 8, 2020 at 5:29
  • The error clearly states that you have some problem with your SQL syntax in line 15. Please provide the code of your program where you are getting the error Commented Jul 8, 2020 at 5:30

1 Answer 1

2
City varchar(255),

I might be mistaken, but it seems that it's not a comma but some other comma like looking character?

Sign up to request clarification or add additional context in comments.

1 Comment

good eyes. well done. MySQL errors are good at pointing at the exact error position. I should of taken more notice.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.