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

博客提到一段Python代码使用PyMySQL操作MySQL时运行报错,错误类型为pymysql.err.ProgrammingError,具体是SQL语法错误。解决办法是将emptystring改为单引号。

源代码:

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值