gpt4 book ai didi

python - 如何修复设置 Django 1.9 应用程序时无法序列化错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:04 24 4
gpt4 key购买 nike

我正在设置 Django 1.9 应用程序 (Python 2),但遇到问题。当我尝试 python manage.py makemigrations 时,出现以下错误:

ValueError: Cannot serialize: [myapp.models.OverwriteStorage object at 0x7fa1b84fc150] There are some values Django cannot serialize into migration files. For more, see https://docs.djangoproject.com/en/1.9/topics/migrations/#migration-serializing

OverwriteStorage 是我包含在 models.py 中的自定义类,它使用 Azure 存储覆盖 Django 的内置存储类(位于 django/core/files/storage.py)。访问上面引用的链接会列出所有 Django 在迁移之前无法序列化的内容。

您建议我做什么来解决这个问题?如果需要,请索取更多信息。

最佳答案

您的存储类必须是可解构的。要点#4 in this checklist 。这意味着,您需要提供 deconstruct()自定义存储类中的方法

类似这样的:

def deconstruct(self):
path = 'python to your storage class'
args = {}
kwargs = {}
return path, args, kwargs

引自文档:

Your storage class must be deconstructible so it can be serialized when it’s used on a field in a migration. As long as your field has arguments that are themselves serializable, you can use the django.utils.deconstruct.deconstructible class decorator for this (that’s what Django uses on FileSystemStorage).

关于python - 如何修复设置 Django 1.9 应用程序时无法序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36389144/

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