python mysql.connector编程错误:1064(42000)

时间:2020-07-08 18:43:54

标签: python mysql mysql-python

有人可以在这里检查我的语法错误吗?我试图在python的mysql.connector中创建一个表,但是无论我做了什么更改,都不断遇到相同的错误。

在较大的程序中运行这段代码,我不断收到错误消息,

for key in keys:
    key_without_pound = key[1:]
    create_table = """CREATE TABLE IF NOT EXISTS {} (
    id int NOT NULL AUTO_INCREMENT,
    user_name varchar NOT NULL,
    tweet varchar NOT NULL,
    followers int NOT NULL,
    likes int NOT NULL,
    retweets int NOT NULL,
    retweeted boolean NOT NULL,
    date datetime NOT NULL,
    PRIMARY KEY (id)
    );""".format(key_without_pound)
    
        
    cursor.execute(create_table)
    print("table {} created in TC".format(key_without_pound))
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 'NOT NULL,
    tweet varchar NOT NULL,
    followers int NOT NULL,
    likes int ' at line 3

During handling of the above exception, another exception occurred:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-8-8a6a88f6a7d2> in <module>
     14 
     15 
---> 16     cursor.execute(create_table)
     17     print("table {} created in TC".format(key_without_pound))

/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 'NOT NULL,
    tweet varchar NOT NULL,
    followers int NOT NULL,
    likes int ' at line 3

/ key_without_pound 是一个简单的字符串,带有'#'符号的截断。

0 个答案:

没有答案