0

I am trying to delete a field's data from Django model. Suppose I have a model named UserData and I want to delete city field for record_Id = 1, without deleting the data from other fields for record_Id = 1. I used:

UserData.objects.filter(city="London").delete()

but it deletes the whole record. I tried this method on SO, but gives attribute error Delete field from standard Django model .

Let me know how to do this. Thanks!

Rishabh Rusia
  • 173
  • 2
  • 4
  • 19

1 Answers1

3

When you want to delete the value of specific field in a row, then it is termed as updating the field's content to null value and not deleting the field. In this case, if you want to update the field's value to null, use following statement.

UserData.objects.filter(record_Id=1).update(city=None)
Vipin Kumar
  • 6,441
  • 1
  • 19
  • 25