Allowing null value in Peewee
Asked Answered
I

1

7

I'm trying to allow null values in some columns of a MySQL database using peewee with bottle. Looking at the docs here I thought that would be quite easy. I set up a class like this:

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

created the table and tried to insert a null value like this:

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

Only for it to hang up on me and say "_mysql_exceptions.OperationalError: (1048, "Column 'Title' cannot be null")". Am I doing something wrong?

Ivetteivetts answered 20/9, 2013 at 22:27 Comment(3)
You said that you "created the table". How exactly did you go about doing this?Halflife
TestClass.create_table(). Table is apparently created correctly, I don't show them in the question but I successfully inserted some none-null entries.Ivetteivetts
Oops, got it, when I originally made the table I created it as (NULL = True), rather than (null = True). Seems to work when I fix that. Thanks guysIvetteivetts
I
10

When table was created, said

Title = pw.Charfield(NULL = True) 

rather than

Title = pw.Charfield(null = True)
Ivetteivetts answered 23/9, 2013 at 14:17 Comment(1)
Peewee will not drop or recreate your tables when you change code. That would be quite disastrous if you had data.Glycogenesis

© 2022 - 2024 — McMap. All rights reserved.