Opened 8 years ago

Closed 5 years ago

#6792 closed Uncategorized (duplicate)

Documentation for FileField does not mention the delete behavior

Reported by: thebitguru <farhan@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: delete file update bug
Cc: sjulean@…, cortland@…, michal.salaban@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


The current documentation for FileField does not mention that django will delete the underlying file in some cases. I had to look through the code to figure out the exact behavior. It would be useful to have this information in the documentation.

Below is what I figured out.

  1. Files are deleted only if there are no other records referring to it.
  2. File is not deleted if you update the record with a new file. I see that #6157 mentions this, but this behavior is inconsistent with point 1 above.
  3. Files are deleted even if a transaction fails. I saw this behavior reported by #6456, but my application does not use transactions so this is more of an FYI.

Change History (8)

comment:1 Changed 8 years ago by edgarsj

  • Keywords bug added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 8 years ago by sjulean

  • Cc sjulean@… added

comment:3 Changed 8 years ago by towjzhou@…

  1. If file field is None, delete() will try to delete the parent folder, and a access error occured.

comment:4 Changed 8 years ago by pixelcort

  • Cc cortland@… added

Is this also the ticket representing the bug where using a ModelForm to change a FileField from one file to another causes the old file to remain on the filesystem?

comment:5 Changed 7 years ago by emes

  • Cc michal.salaban@… added

comment:6 Changed 6 years ago by anonymous

@pixelcort: probably not, it was #6157 (marked as wontfix)
I think there should be some kind of delete=bool or delete_on_modify=bool for image and file fields.

comment:7 Changed 5 years ago by jezdez

FTR, there is a pretty good summary of the issue at

comment:8 Changed 5 years ago by julien

  • Resolution set to duplicate
  • Severity set to Normal
  • Status changed from new to closed
  • Type set to Uncategorized

Files aren't deleted any more, but the documentation still needs to be improved. Since the issue is now actually the opposite one, I'll close as dupe of #15588 which is more up-to-date.

Note: See TracTickets for help on using tickets.
Back to Top