Thursday, December 31, 2015

Strange behaviour while deleting related object

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'.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa4a2b19-eaab-4e16-a255-09e910d0444d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment