If I change ImageFIeld.upload_to parameter, should it move previously uploaded files upon migration?

110 Views Asked by At

I have a Django model with

...
image = models.ImageField(default=None, upload_to=settings.PHOTO_UPLOAD_TO)
...

I have changed the value of settings.PHOTO_UPLOAD_TO, but the files have remained where they were, and the database entries also don't seem to have changed. A newly added image is placed in the correct new location, but not the old ones. Is it an expected behaviour? Is there a way to migrate the image locations? I would like to slightly change the directory/URL structure of my project.

1

There are 1 best solutions below

2
On

The path of a FileField/ImageField is stored relative to MEDIA_ROOT, so if you want to move the files to the new upload_to folder, you're gonna need to put that in your migration yourself (like you suggested).