开发者

force_update in save method

开发者 https://www.devze.com 2023-01-05 09:43 出处:网络
I have to update an entry in my django model. I have used force开发者_StackOverflow_update in save method like this:

I have to update an entry in my django model.

I have used force开发者_StackOverflow_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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消