ValueError:无法序列化:<google.oauth2.service_account.credentials object =“” at =“” 0x7f292c774908 =“”>

时间:2019-04-09 19:44:04

标签: django django-storage

我正在使用Google Cloud的Django存储,但是在迁移时会抛出错误

ValueError: Cannot serialize: <google.oauth2.service_account.Credentials object at 0x7f292c774908> There are some values Django cannot serialize into migration files.

我还使用了可分解的装饰器,但问题仍然存在。

from django.utils.deconstruct import deconstructible
from google.oauth2 import service_account
from storages.backends.gcloud import GoogleCloudStorage

GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
    "/path/to/my-key.json"
)

@deconstructible
class MyGoogleCloudStorage(GoogleCloudStorage):
    pass

我的models.py

class Company(models.Model):
    image_1 = models.ImageField(
       upload_to=image_directory_path,
       storage=MyGoogleCloudStorage(
            credentials=GS_CREDENTIALS,
            bucket_name='webdeveloper',
            default_acl='publicRead'
        ))

    image_2 = models.ImageField(
       upload_to=image_directory_path,
       storage=MyGoogleCloudStorage(
            credentials=GS_CREDENTIALS,
            bucket_name='webdeveloper',
            default_acl='publicRead'
        ))

我在做什么错。非常令人沮丧

0 个答案:

没有答案