Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对插入功能有疑问。如果我有一组要插入的对象[坏,好,好]。如果第一个对象是坏的,并且对象插入操作将失败,那么即使对象是好的,其余的对象也永远不会命中数据库。
我该如何处理?
您可以在保存之前验证模型实例以确保它们有效,例如:
valid_docs = [d for d in docs if d.validate()]
continue_on_error=True或作为例如传递write_options:
continue_on_error=True
write_options
Doc.objects.insert(docs, write_options={"continue_on_error": True})