Strange behaviour while deleting related object

16 views
Skip to first unread message

Dheerendra Rathor

unread,
Dec 31, 2015, 6:06:39 PM12/31/15
to Django users
Hello All,

I have a model like this:

class Concept(models.Model):
    tag = models.ForeignKey(Tag, null=True, on_delete=models.SET_NULL)

Now, I've a piece of code in my view:

if concept.tag:
    concept.tag.delete()
concept.save()


I'm getting this error in line concept.save()

ValueError: save() prohibited to prevent data loss due to unsaved related object 'tag'.
Reply all
Reply to author
Forward
0 new messages