python - 升级到 Django 1.7。获取错误 : Cannot serialize: <storages. backends.s3boto.S3BotoStorage 对象

标签 python django python-2.7 boto django-storage

我正在尝试将 Django 应用程序从 Django 1.6.6 升级到 1.7,并且我使用的是 Python 2.7.8。当我运行 python manage.py makemigrations 时,出现以下错误:

ValueError: Cannot serialize: <storages.backends.s3boto.S3BotoStorage object at 0x11116eed0>
There are some values Django cannot serialize into migration files.

相关代码如下:

protected_storage = storages.backends.s3boto.S3BotoStorage(
      acl='private',
      querystring_auth=True,
      querystring_expire=3600,
    )


    class Document(models.Model):
        ...
        file = models.FileField(upload_to='media/docs/', max_length=10000, storage=protected_storage)

        def __unicode__(self):
            return "%s" % self.candidate

        def get_absolute_url(self):
            return reverse('documents', args=[str(self.pk)])

我已阅读迁移文档并了解类似的问题 here ,但我一直无法解决这个问题。我的应用程序使用 django-storages 和 boto 将文件保存到 Amazon S3。感谢您的帮助。

最佳答案

只需创建一个可解构的子类并使用它即可。

from django.utils.deconstruct import deconstructible


@deconstructible
class MyS3BotoStorage(S3BotoStorage):
    pass

关于python - 升级到 Django 1.7。获取错误 : Cannot serialize: <storages. backends.s3boto.S3BotoStorage 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25648335/

相关文章:

python - 从图中删除节点

python - 使用 Pandas 在excel文件中搜索column_names的起始列和行

python - 如何根据特定行中的值对 numpy 数组进行排序?

mysql - Django - Charfield 在我的 BD 中创建一个项目

python - Tkinter 消失的 PhotoImage 问题

python - 读取配置文件时出现 ConfigParser.MissingSectionHeaderError Python

python - django.db.migrations.RenameModel 和 AutoField 序列名称

python - Django - 显示图像字段

python - Pyramid - 为文件上传表单编写单元测试

Python 打印 unicode 列表