... )。各バージョン系列の最新リリースのみを公式にサポートし、最新リリースを使用することを 強く推奨 します。 Django 2.2 の新機能 Constraints The new CheckConstraint and UniqueConstraint classes enable adding custom database constraints. Constraints are added to m ... odels using the Meta.constraints option. マイナーな機能 django.contrib.admin Added a CSS class to the column headers of TabularInline . django.contrib.auth ... licts parameter of QuerySet.bulk_create() to True tells the database to ignore failure to insert rows that fail uniqueness constraints or other checks. The new ExtractIsoYear function extracts ISO-8601 week-numbering years from DateField and DateTimeField , ... ... tching is case insensitive. If not provided, the default index type is GIST . Changed in Django 6.1: Support for exclusion constraints using Hash indexes was added. condition ExclusionConstraint. condition 行の一部に制約をかける条件を指定する Q オブジェクト ... ラメータを設定します。使用可能な値は Deferrable.DEFERRED または Deferrable.IMMEDIATE です。例: from django.contrib.postgres.constraints import ExclusionConstraint from django.contrib.postgres.fields import RangeOperators from django.db.models import Deferrab ... 。 例 次の例では、キャンセルされた予約を考慮せずに、同じ部屋での重複する予約を制限しています。 from django.contrib.postgres.constraints import ExclusionConstraint from django.contrib.postgres.fields import DateTimeRangeField , RangeOperators from django.db i ... ... 約には常にユニークな名前を指定する必要があります。また、通常は抽象基底クラスで制約を指定することはできません。なぜなら Meta.constraints オプションはサブクラスに継承され、そのたびに( name を含む)属性がまったく同じ値になってしまうからです。名前の衝突を回避す ... 制約は、トランザクションが終了するまで実行されません。即時 (IMMEDIATE) 制約は、すべてのコマンドの直後に実行されます。 Unique constraints with condition , include , opclasses , or expressions may be implemented as unique indexes rather than unique constraints. ... nulls_distinct = False ) これは、 ordering カラムに NULL 値を格納できるのは1行だけというユニーク制約を作成します。 Unique constraints with nulls_distinct are ignored for databases besides PostgreSQL. violation_error_code UniqueConstraint. violation_error_c ... ... プデートパスが必要な場合は、 pytz_deprecation_shim と USE_DEPRECATED_PYTZ 移行用設定の使用が推奨されます。 Functional unique constraints The new *expressions positional argument of UniqueConstraint() enables creating functional unique constraints on expressio ... l ): first_name = models . CharField ( max_length = 255 ) last_name = models . CharField ( max_length = 255 ) class Meta : constraints = [ UniqueConstraint ( Lower ( "first_name" ), Lower ( "last_name" ) . desc (), name = "first_last_name_unique" , ), ] Fun ... ctional unique constraints are added to models using the Meta.constraints option. scrypt password hasher The new scrypt password hasher is more secur ... ... s support as it evolves. See 非同期クエリ for details and limitations. 制約のバリデーション Check , unique , and exclusion constraints defined in the Meta.constraints option are now checked during model validation . Form rendering accessibility In order to ... t values. SpGistIndex now supports covering indexes on PostgreSQL 14+. ExclusionConstraint now supports covering exclusion constraints using SP-GiST indexes on PostgreSQL 14+. The new default_bounds attribute of DateTimeRangeField and DecimalRangeField allo ... . after database server restart. QuerySet.bulk_create() now supports updating fields when a row insertion fails uniqueness constraints. This is supported on MariaDB, MySQL, PostgreSQL, and SQLite 3.24+. QuerySet.iterator() now supports prefetching related o ... ... e model as a whole - Model.clean() Validate the field uniqueness - Model.validate_unique() 制約を検証する - Model.validate_constraints() モデルの full_clean() メソッドを使うと、4 つ全てのステップが実行されます。 When you use a ModelForm , the call to is_val ... fields from the ModelForm that require validation. Model. full_clean ( exclude = None , validate_unique = True , validate_constraints = True ) [ソース] This method calls Model.clean_fields() , Model.clean() , Model.validate_unique() (if validate_unique is ... True ), and Model.validate_constraints() (if validate_constraints is True ) in that order and raises a ValidationError that has a message_dict attribute containi ... ... nds against an existing database may generate SQL with the new form of constraint name, while the database itself contains constraints named in the old form; this will cause the database server to raise an error message about modifying nonexistent constrain ... . Examine the output of manage.py sqlall to see the new-style constraint names, and use that as a guide to rename existing constraints in your database. Name changes in manage.py A few of the options to manage.py have changed with the addition of fixture su ... ... ... このバグは、 Meta.constraints を使用したモデル検証がクラッシュする原因となっていました ( #34205 )。 ... ... lds = [ "first_name" ], name = "first_name_idx" ), ] unique_together Options. unique_together 代わりに UniqueConstraint を constraints オプションとともに使用してください。 UniqueConstraint は unique_together よりも多くの機能を提供します。 unique_together は ... 用してみてください。 制約に違反したときにモデル検証中に発生する ValidationError は unique_together エラーコードを持ちます。 constraints Options. constraints モデルに定義したい 制約 のリスト: from django.db import models class Customer ( models . Model ): age ... = models . IntegerField () class Meta : constraints = [ models . CheckConstraint ( condition = models . Q ( age__gte = 18 ), name = "age_gte_18" ), ] verbose_name Options. ve ... 2026年10月08日