Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Peewee中允许空值_Python_Mysql_Peewee - Fatal编程技术网

Python 在Peewee中允许空值

Python 在Peewee中允许空值,python,mysql,peewee,Python,Mysql,Peewee,我正在尝试使用peewee with Battle在MySQL数据库的某些列中允许空值。看着这些文件,我觉得这很容易。我设立了一个这样的班级: class TestClass(MySQLModel): Title = pw.CharField(null = True) myDB.connect() x = TestClass.create(Title = None) x.save() 创建表并尝试插入空值,如下所示: class TestClass(MySQLModel): Title

我正在尝试使用peewee with Battle在MySQL数据库的某些列中允许空值。看着这些文件,我觉得这很容易。我设立了一个这样的班级:

class TestClass(MySQLModel):
Title = pw.CharField(null = True)
myDB.connect()
x = TestClass.create(Title = None)   
x.save()
创建表并尝试插入空值,如下所示:

class TestClass(MySQLModel):
Title = pw.CharField(null = True)
myDB.connect()
x = TestClass.create(Title = None)   
x.save()

只有它挂断我的电话并说“
\u mysql\u exceptions.OperationalError:(1048,“列'Title'不能为空”)
”。我做错什么了吗?

当创建表时,他说

Title = pw.Charfield(NULL = True) 
而不是

Title = pw.Charfield(null = True)

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

您说过您“创建了表”。你到底是怎么做的?
TestClass.create\u table()
。表的创建显然是正确的,我没有在问题中显示它们,但我成功地插入了一些非空条目。哎呀,得到了,当我最初创建表时,我将其创建为
(null=True)
,而不是
(null=True)
。当我修好它的时候,它似乎起作用了。谢谢,Guyspewee在您更改代码时不会删除或重新创建您的表。如果你有数据,那将是非常灾难性的。