Search code examples
pythonsqliteflaskpeewee

Incrementing a value in Flask with peewee


I have been making an application with Flask and Peewee and I am trying to increment a value by one in the database using the update() function.

Here is the problem:

models.User.update(
        likes+=1
        ).execute()

This is not working and I simply get the error:

  File "app.py", line 171
   love+=1
     ^
  SyntaxError: invalid syntax

Thanks for any help.


Solution

  • The correct syntax is

    User.update(likes=User.likes+1).execute()
    

    See Atomic Updates for details.