当删除具有ImageField字段的对象时,图像文件未被删除 [英] Image file not deleted when object with ImageField field is deleted

查看:113
本文介绍了当删除具有ImageField字段的对象时,图像文件未被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型图片 ImageField 。删除 Picture 的实例时, ImageField 中设置的文件不会被删除。

I've got a model Picture with an ImageField. When deleting an instance of Picture, the file set in the ImageField is not deleted.

这是一个bug吗?如何执行?

Is it a bug? How can I do it?

推荐答案

删除与 FileField s和 ImageField 在Django 1.3中有意删除。请参阅门票#6456 。 Django广泛使用事务来防止请求发生错误的数据损坏。如果删除事务被回滚,则在文件从文件系统中删除后,您现在有一个记录指向不存在的文件。所有要求自动删除的票据已经被简要标记为不会修复,所以这不会改变。

Deletion of files associated with FileFields and ImageFields was intentionally removed in Django 1.3. See ticket #6456. Django uses transactions extensively to prevent data corruption if something goes wrong with the request. If a deletion transaction is rolled-backed, after the file has been deleted from the filesystem, then you now have a record pointing to a non-existent file. All tickets asking for automatic deletion to return have been summarily marked "Won't Fix", so this is not going to change.

有关变通方法,请参阅此前StackOverflow问题

For workarounds, see this previous StackOverflow question.

这篇关于当删除具有ImageField字段的对象时,图像文件未被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆