Replacing a Django image doesn't delete original

前端 未结 8 1312
死守一世寂寞
死守一世寂寞 2020-12-13 14:43

In Django, if you have a ImageFile in a model, deleting will remove the associated file from disk as well as removing the record from the database.

Shouldn\'t replac

8条回答
  •  温柔的废话
    2020-12-13 15:03

    Shouldn't replacing an image also remove the unneeded file from disk?

    In the olden days, FileField was eager to clean up orphaned files. But that changed in Django 1.2:

    In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to several potentially serious data-loss scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.2.5, FileField will never delete files from the backend storage.

提交回复
热议问题