升级到Django 1.7。获取错误:无法序列化:<存储。后端.s3boto.S3BOTORAGE目标

2024-04-29 20:01:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将django应用程序从django 1.6.6升级到1.7,并使用python2.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.

下面是相关代码:

^{pr2}$

我读过迁移文档,也读过类似的问题here,但我一直无法解决这个问题。我的应用程序使用django存储和boto将文件保存到amazons3上。感谢任何帮助。在


Tags: djangopy应用程序objectmanage错误serializeat
2条回答

这里的基本问题是,您正在尝试使用django1.7和一个包(django-storages)一起使用,该包似乎还没有更新到可以使用该版本。在

以下是documentation的一些摘录,以解释正在发生的事情:

Migrations are just Python files containing the old definitions of your models - thus, to write them, Django must take the current state of your models and serialize them out into a file.

While Django can serialize most things, there are some things that we just can’t serialize out into a valid Python representation - there’s no Python standard for how a value can be turned back into code.

You can let Django serialize your own custom class instances by giving the class a deconstruct() method.

所以这里的解决方案是给类storages.backends.s3boto.S3BotoStorage一个deconstruct()方法。这可能与应用^{}类修饰符一样简单。在

大概包在某个时候会包含这个变更(或者可能主分支已经有了它?),但你也可以自己修补。在

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

from django.utils.deconstruct import deconstructible


@deconstructible
class MyS3BotoStorage(S3BotoStorage):
    pass

相关问题 更多 >