Hosted Media Files get cleared after i redeploy github repo?

I hosted my database on railway, when i upload images from my admin section, it shows up in the designated place and everything works fine. The problem starts when i make a change to the github repo and redeploy, all the images that i upload get cleared and i have to redeploy the images, NOTE: texts get created and does not clear, only the images that i uploaded get cleared when i redeploy my github repo, what is the problem here and what can i do to resolve this please?

Normally when you deploy a django app you must decide where you should store the media files. This can be stored on the same server as the app and you manage the disk space and all the stuff related to this. In your specific case the platform abstracts the server and set it ups for you, so maybe this is not the way to go.

This is probably happening because whenever you push some code change, there’s a new “machine” that will host your code.

Search on your service if they have a file bucket, like others providers have (s3 from AWS), you going to need to change your settings to match this file hosting service.


I have the same issue. Did you find a solution?

1 Like

Yes, you need to host your static and media files on AWS S3, Cloudinary, Google Cloud, or Microsoft Azure.
Whenever you re-deploy your app, the hosting platform (heroku, railway or Digital Ocean) provision a new app for your new deployed app, which would clear all the existing static or media

That was the solution.

1 Like