How to get the user email after deletion in Django?

Question:

I was working with the settings.AUTH_USER_MODEL and I want the email of the user to remain( after the user deleted). The user is a foreign key in my model.
Here is the code

class Text(models.Model):
    title = models.CharField(max_length=45)
    text = models.TextField()
    user= models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(??) )  # TODO : should change( remain email from the deleted user)
Asked By: Montio5

||

Answers:

Try this:

user= models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)

That saves the deleted user’s foreignkey.

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.