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?

Christoph
  • 47,569
  • 8
  • 87
  • 187
Alex S
  • 4,726
  • 7
  • 39
  • 67
  • You said that you "created the table". How exactly did you go about doing this? – Mark Hildreth Sep 20 '13 at 22:41
  • `TestClass.create_table()`. Table is apparently created correctly, I don't show them in the question but I successfully inserted some none-null entries. – Alex S Sep 20 '13 at 22:42
  • 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 guys – Alex S Sep 20 '13 at 22:46

1 Answers1

9

When table was created, said

Title = pw.Charfield(NULL = True) 

rather than

Title = pw.Charfield(null = True)
Alex S
  • 4,726
  • 7
  • 39
  • 67
  • Peewee will not drop or recreate your tables when you change code. That would be quite disastrous if you had data. – coleifer Sep 24 '13 at 16:22