Skip to content
Advertisement

Django throws ValueError: save() prohibited to prevent data loss due to unsaved related object save method

I am trying to create some objects of model ABC in from save method of XYZ model, when a XYZ models object is created. See the below code for reference :

JavaScript

And here are the error lines :

JavaScript

Advertisement

Answer

You’re going to want to call super.save() on your MatchDetail before you created your ContestDetail object, not after, as you have it. Until super is called, your self object has no primary key (assuming it’s a new object being saved)

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement