0

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)
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Montio5
  • 60
  • 7
  • Refer this link : [https://stackoverflow.com/questions/47917926/custom-the-on-delete-param-function-in-django-model-fields](https://stackoverflow.com/questions/47917926/custom-the-on-delete-param-function-in-django-model-fields) – Deepak Tripathi Oct 21 '21 at 06:50

1 Answers1

1

Try this:

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

That saves the deleted user's foreignkey.

ouflak
  • 2,458
  • 10
  • 44
  • 49