把数据库字段的默认值设为空字符串,解决内存问题。完美解决pymysql.err.ProgrammingError: (1064)

源代码:

create_sql = """create table if not exists user(
user_id int(10) unsigned auto_increment,
user_name varchar(30) not null default emptystring,
user_nickname varchar(30) not null default emptystring,
user_postbox varchar(30) not null default emptystring,
user_phontNumber varchar(11)  not null default emptystring,
user_password varchar(100) not null default emptystring,
primary key (user_id)
)"""





File "F:\Python\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "F:\Python\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.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 'emptystring,\nuser_nickname varchar(30) not null default emptystring,\nuser_postbo' at line 3")



上面这段代码看起来没有问题,可是运行起来就报错,pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual tha 这时只要把emptystring改为’ '单引号就可以了。

create_sql = """create table if not exists user(
user_id int(10) unsigned auto_increment,
user_name varchar(30) not null default ' ',
user_nickname varchar(30) not null default ' ',
user_postbox varchar(30) not null default ' ',
user_phontNumber varchar(11)  not null default ' ',
user_password varchar(100) not null default ' ',
primary key (user_id)
)"""


```F:\Python\python.exe F:/PYthon练习/数据库MySQL/MySQL练习/Pymysql练习.py

Process finished with exit code 0

你可能感兴趣的:(PyMySQL,Python,MySQL,PyMySQL,内存优化)