编程语言
首页 > 编程语言> > python – 在Peewee中允许空值

python – 在Peewee中允许空值

作者:互联网

我正在尝试在使用peewee with bottle的MySQL数据库的某些列中允许空值.看看文档here,我觉得这很容易.我设置了这样一个类:

class TestClass(MySQLModel):
Title = pw.CharField(null = True)

创建了表并尝试插入如下的null值:

myDB.connect()
x = TestClass.create(Title = None)   
x.save()

只是为了挂断我并说“_mysql_exceptions.OperationalError:(1048,”Column’Title’不能为空“)”.难道我做错了什么?

解决方法:

当表创建时,说

Title = pw.Charfield(NULL = True) 

而不是

Title = pw.Charfield(null = True)

后来改为正确的版本,但没有重新制作表格.通过更改类来修复,然后删除表并使用更正的类重新创建它.

标签:python,mysql,peewee
来源: https://codeday.me/bug/20190624/1282248.html