Opened 12 years ago

Closed 9 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: no UI/UX: no


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 12 years ago by edgarsj

Keywords: bug added
Triage Stage: UnreviewedAccepted

comment:2 Changed 12 years ago by sjulean

Cc: sjulean@… added

comment:3 Changed 12 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 11 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 11 years ago by Michał Sałaban

Cc: michal.salaban@… added

comment:6 Changed 10 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 9 years ago by Jannis Leidel

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

comment:8 Changed 9 years ago by Julien Phalip

Resolution: duplicate
Severity: Normal
Status: newclosed
Type: 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