Search code examples
pythonpeewee

peewee interpretes conditions in where clause


I am trying to implement peewee ORM in my project, but I have a weird issue:

class Server(peewee.Model):
    name = peewee.CharField

    class Meta:
        database = db


print Server.select().where(Server.name == 'postfix').sql()

returns:

('SELECT `t1`.`id` FROM `server` AS t1 WHERE %s', [False])

Running python 2.7.6 w/ peewee 2.6.4


Solution

  • name needs to be an instance of peewee.CharField, not the class itself. So your code should be:

    class Server(peewee.Model):
        name = peewee.CharField() # instantiate it!
    
        class Meta:
            database = db
    
    
    print Server.select().where(Server.name == 'postfix').sql()