ValueError:无法序列化:< myproject.storage.AzureStorage对象在0x7f85185e66d0> [英] ValueError: Cannot serialize: <myproject.storage.AzureStorage object at 0x7f85185e66d0>
问题描述
我正在尝试使用 AzureStorage 将天蓝存储与django 1.7应用程序连接起来。
I am trying to use AzureStorage to for connecting azure storage with django 1.7 app .
models.py
models.py
from django.db import models
from myproject.storage import AzureStorage
class MyModel(models.Model):
my_file = models.FileField(upload_to="files", storage=AzureStorage(container="media"))
my_image = models.ImageField(upload_to="images", storage=AzureStorage(container="media"))
但是,当我尝试makemigrations我得到:
But when I try to makemigrations I am getting :
ValueError: Cannot serialize: <myproject.storage.AzureStorage object at 0x7f85185e66d0>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing
究竟什么不能序列化?
推荐答案
您是否从升级到Django 1.7。获取错误:无法序列化:< storages.backends.s3boto.S3BotoStorage对象,这是一个类似的问题。复制了这里的答案,以供您快速参考:
Have you checked the solution from Upgrading to Django 1.7. Getting error: Cannot serialize: <storages.backends.s3boto.S3BotoStorage object which was a similar question asking before. Copied the answer here for your quick reference:
这里的基本问题是您尝试使用Django 1.7与
包装(django-storages)似乎没有更新到
与该版本一起工作。
The basic issue here is that you are trying to use Django 1.7 with a package (django-storages) that doesn't appear to have been updated to work with that version yet.
以下是文档中的一些摘录说明什么是
发生:
Here are some excerpts from the documentation to explain what is happening:
迁移只是包含
您的模型的旧定义的Python文件 - 因此,要编写它们,Django必须采取您的模型的当前状态
,并将它们序列化为一个文件。
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.
尽管Django可以序列化大部分内容,但有一些我们
只是无法序列化为一个有效的Python表示 - 有一个
没有Python标准,如何一个值可以转回代码。
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.
你可以让Django序列化您自己的自定义类实例通过给
该类一个deconstruct()方法。
You can let Django serialize your own custom class instances by giving the class a deconstruct() method.
所以这里的解决方案是给类
storages.backends.s3boto.S3BotoStorage一个解构()方法。那个
可能会像应用@deconstructible类
decorator一样简单。
So the solution here is to give the class storages.backends.s3boto.S3BotoStorage a deconstruct() method. That will probably be as easy as applying the @deconstructible class decorator.
大概该包将会在某个时候(或
也许主分公司已经有了吗?),但是你也可以自己修补
。
Presumably the package will incorporate this change at some point (or perhaps the master branch already has it?), but you could also just patch it yourself.
请如果解决方案(使用django.utils.deconstruct中的@deconstructible类装饰器添加deconstruct()方法),您可以随时通知我们。
Please feel free to let us know if the solution (use the @deconstructible class decorator from django.utils.deconstruct to add the deconstruct() method) does not work for you.
这篇关于ValueError:无法序列化:< myproject.storage.AzureStorage对象在0x7f85185e66d0>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!