Force_update in save method

I need to update an entry in my django model.

I used force_update in the save method, for example:

register = rform.save(commit=False)
register.user = request.user
register.save(register.user,force_update=True)

But this gives me an error:

"ValueError at /status/
Cannot force both insert and updating in model saving."

How can i solve this?

+3
source share
1 answer

You cannot update an instance of a model until it is present in the database. First you have to save it in the database, only then it will force_update.

See the documentation here.

+4
source

Source: https://habr.com/ru/post/1752975/


All Articles