本文档涵盖了 Model 类的功能。关于模型的更多信息,请参见 模型参考指南的完整列表。
DoesNotExist¶当没有找到预期的对象时,ORM 会引发这个异常。例如, QuerySet.get() 将在没有找到给定查找对象时引发该异常。
Django 提供了一个 DoesNotExist 的异常作为每个模型类的属性,用来标识找不到的对象类,允许你为某个模型类捕捉异常。该异常是 django.core.exceptions.ObjectDoesNotExist 的一个子类。
MultipleObjectsReturned¶当给定的查找找到多个对象时, QuerySet.get() 会引发这个异常。
Django 提供了一个 MultipleObjectsReturned 的异常作为每个模型类的属性,用于识别发现多个对象的对象类,允许你为某个模型类捕捉异常。该异常是 django.core.exceptions.MultipleObjectsReturned 的一个子类。
NotUpdated¶This exception is raised when a forced update of a Model instance
does not affect any rows.
Django provides a NotUpdated exception as an attribute of each model
class to identify the class of object that could not be updated, allowing
you to catch exceptions for a particular model class. The exception is a
subclass of django.core.exceptions.ObjectNotUpdated and inherits
from django.db.DatabaseError for backward compatibility reasons.
objects¶12月 22, 2025