gpt4 book ai didi

python - ValueError : Cannot serialize:

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:04 25 4
gpt4 key购买 nike

我正在尝试使用AzureStorage用于将 azure 存储与 django 1.7 应用程序连接。

模型.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"))

但是当我尝试进行迁移时,我得到:

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

到底是什么无法序列化?

最佳答案

您检查过 Upgrading to Django 1.7. Getting error: Cannot serialize: <storages.backends.s3boto.S3BotoStorage object 的解决方案吗?这是之前问过的类似问题。将答案复制到此处供您快速引用:

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:

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.

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() 方法)不适合您,请随时告诉我们。

关于python - ValueError : Cannot serialize: <myproject. storage.AzureStorage 对象位于 0x7f85185e66d0>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31093681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com