python – Django 1.7 makemigrations – ValueError:无法序列化函数:lambda

前端之家收集整理的这篇文章主要介绍了python – Django 1.7 makemigrations – ValueError:无法序列化函数:lambda前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我切换到Django 1.7.当我为我的应用程序尝试makemigrations时,它会崩溃.崩溃报告是:
Migrations for 'roadmaps':
  0001_initial.py:
    - Create model DataQualityIssue
    - Create model MonthlyChange
    - Create model Product
    - Create model ProductGroup
    - Create model RecomendedStack
    - Create model RecomendedStackMembership
    - Create model RoadmapMarket
    - Create model RoadmapUser
    - Create model RoadmapVendor
    - Create model SpecialEvent
    - Create model TimelineEvent
    - Create model UserStack
    - Create model UserStackMembership
    - Add field products to userstack
    - Add field viewers to userstack
    - Add field products to recomendedstack
    - Add field product_group to product
    - Add field vendor to product
    - Add field product to dataqualityissue
Traceback (most recent call last):
  File "manage.py",line 29,in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",line 385,in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",line 377,in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",line 288,in run_from_argv
    self.execute(*args,**options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",line 338,in execute
    output = self.handle(*args,**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py",line 124,in handle
    self.write_migration_files(changes)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py",line 152,in write_migration_files
    migration_string = writer.as_string()
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 129,in as_string
    operation_string,operation_imports = OperationWriter(operation).serialize()
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 80,in serialize
    arg_string,arg_imports = MigrationWriter.serialize(item)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 245,in serialize
    item_string,item_imports = cls.serialize(item)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 310,in serialize
    return cls.serialize_deconstructed(path,args,kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 221,in serialize_deconstructed
    arg_string,arg_imports = cls.serialize(arg)
  File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/writer.py",line 323,in serialize
    raise ValueError("Cannot serialize function: lambda")
ValueError: Cannot serialize function: lambda

我在https://code.djangoproject.com/ticket/22892找到了关于这个的说明

还有文档https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values链接

但它并没有让我更清楚.错误消息没有给我一个线索在哪里寻找问题.

有没有办法如何检测究竟是什么线导致问题?

任何提示

解决方法

我们在自定义字段定义中使用lambda时遇到了这个问题.

它很难被发现,因为它未在回溯中列出,并且在使用此类自定义字段的特定模型上不会引发错误.

我们的修复方法

>检查所有自定义字段(即使在第三方库中)>将lambda更改为callable,它在模块中定义(即不在自定义字段类中)

原文链接:https://www.f2er.com/python/186327.html

猜你在找的Python相关文章