lp1051
lp1051

Reputation: 501

Django model FileField with dynamic storage location in migration

I need to store file outside MEDIA_ROOT so I use this approach

from django.core.files.storage import FileSystemStorage
from django.db import models
from myproject.settings import SOME_DIR

fs = FileSystemStorage(location=SOME_DIR)


class Car(models.Model):
    photo = models.ImageField(storage=fs)

Now, when I makemigrations the result is something like:

migrations.AlterField(
        model_name='car',
        name='photo',
        field=models.ImageField(storage=django.core.files.storage.FileSystemStorage(location='C:/temp/documents')),
    ),

The problem is that my local path to SOME_DIR is hardcoded in migration file. So when I push it to production server, where SOME_DIR is /home/xyz/documents, I get warning:

Your models in app(s): 'x' have changes that are not yet reflected in a migration, and so won't be applied.

Is there any way to suppress the warning or change my code, so it won't use the dynamic location path in migration file? I use Django 4.2, but I think it's the same in all versions.

Thanks a lot for help

Upvotes: 0

Views: 41

Answers (0)

Related Questions