Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force_update in save method

I have to update an entry in my django model.

I have used force_update in save method like this:

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

But it gives me an error:

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

How can I resolve this?

like image 294
MajorGeek Avatar asked Jul 03 '10 13:07

MajorGeek


1 Answers

You cannot update a model instance until it is already there in the database. You should save it to the database first, only then does force_update become applicable.

See the documentation here.

like image 148
ashish singh Avatar answered Nov 13 '22 09:11

ashish singh