theriverman / django-minio-backend

Minio Backend for Django
https://pypi.org/project/django-minio-backend/
MIT License
111 stars 22 forks source link

change bucket_name in model #41

Closed Mahdi-Ba closed 1 year ago

Mahdi-Ba commented 1 year ago

Hello, dears Imagine I've got the below code in the model e.x bucket_name is sample

class Image(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    file = models.FileField(verbose_name="Object Upload",
                            storage=MinioBackend(bucket_name='sample'),
                            upload_to=iso_date_prefix)

when changing the model like below e.x bucket_name is test and wanna make migration and migration

class Image(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    file = models.FileField(verbose_name="Object Upload",
                            storage=MinioBackend(bucket_name='test'),
                            upload_to=iso_date_prefix)

I see this error because the sample exists in the last migration and I force added sample in the public or private bucket in settings to prevent error how to fix it? must be declared either in MINIO_PRIVATE_BUCKETS or MINIO_PUBLIC_BUCKETS') django_minio_backend.utils.configuration error: The configured bucket (punto) must be declared either in MINIO_PRIVATE_BUCKETS or MINIO_PUBLIC_BUCKETS

theriverman commented 1 year ago

HI @Mahdi-Ba, You're getting this error because the migration(s) contain the old bucket_name value. See the file(s) in your migrations folder next to your model and you'll see a row like this: https://github.com/theriverman/django-minio-backend/blob/abeed73bb039a5566858c3390660946ce5b09b9b/DjangoExampleApplication/migrations/0001_initial.py#L31

This is a limitation caused by Django itself. See ticket/23159 for more.

As a workaround, you could manually change the values for each bucket_name occurrence in the migration file(s).