[Answer]-How to delete all django media so I can start fresh?

1👍

If you use django-extensions there is a management command to show you all files that are not linked to any object. You can try:

python manage.py unreferenced_files

If you want to delete these files you can use this command

python manage.py unreferenced_files | xargs -I{} rm -v {}

You can also make a cron job to periodically delete these files

If there is a folder in which you upload files and they are not linked to a model and you don’t want to delete them (like if you use django-filebrowser) then you can pipe a grep with correct parameters before piping xargs

0👍

Yes, you can manually delete media files for records deleted in the database.

Media files are not deleted automatically because of the transaction issues. For example you deleted the model and the image and then transaction is rolled back – deleted record will be “restored” to the db but image will be lost.

Leave a comment