... ョンを扱う一般的な方法は、各リクエストをトランザクションでラップすることです。この動作を有効化したい各データベースの設定で、 ATOMIC_REQUESTS を True にセットしてください。 これは、次のように動作します。まず、ビュー関数を呼び出す前に、Django はトランザクシ ... ンをコミットします。もしビューが例外を生成した場合は、Django はトランザクションをロールバックします。 ビューのコード (通常は atomic() コンテキストマネージャー) の中で、セーブポイントを使ったサブトランザクションを扱うことができます。ただし、ビューの最後で ... ポンスを送信開始した後にエラーを扱う適切な方法が存在しないからです。 実際には、この機能はすべてのビュー関数を以下で説明する atomic() デコレータでラップします。 あなたのビューの実行だけがトランザクションで閉じられることに注意してください。ミドルウェアはト ... ... では、マイグレーションはデフォルトでトランザクション内で実行されます。大きなテーブルに対してデータ移行を行う場合などには、 atomic 属性を False に設定することで、トランザクション内で移行が実行されないようにすることができます: from django.db import migra ... tions class Migration ( migrations . Migration ): atomic = False Within such a migration, all operations are run without a transaction. It's possible to execute parts of the migra ... tion inside a transaction using atomic() or by passing atomic=True to RunPython . 以下は、大きなテーブルを小さなバッチで更新する、非アトミックなデータマイグレーシ ... ... ango.db.models.functions.Now を補完するもので、現在のステートメントの日時を返します。 Note that only the outermost call to atomic() sets up a transaction and thus sets the time that TransactionNow() will return; nested calls create savepoints which do ... ... ns now allow using transforms. See 式はトランスフォーム(Transform)を参照できる for details. The new durable argument for atomic() guarantees that changes made in the atomic block will be committed if the block exits without errors. A nested atomic bl ... ... der this simplified example: @task def my_task ( thing_num ): Thing . objects . get ( num = thing_num ) with transaction . atomic (): Thing . objects . create ( num = 1 ) my_task . enqueue ( thing_num = 1 ) To prevent the scenario where my_task runs be ... to enqueue() via functools.partial() : from functools import partial from django.db import transaction with transaction . atomic (): Thing . objects . create ( num = 1 ) transaction . on_commit ( partial ( my_task . enqueue , thing_num = 1 )) Task res ... ... 要素を渡します。これは特に処理を逆の順序で行いたい場合に有用です。 RunPython class RunPython ( code , reverse_code = None , atomic = None , hints = None , elidable = False ) [ソース] マイグレーション履歴を反映して独自の Python コードを実行します。 code ... ンドを利用中に schema_editor を利用しようとするとクラッシュを引き起こす場合があります。このような場合は、 RunPython に対して atomic=False を渡してください。 トランザクション中の DDL 使用をサポートしているデータベース(SQLite や PostgreSQL)においては、 Run ... on オペレーションが 非アトミックなマイグレーション の一部である場合、そのオペレーションは RunPython オペレーションに対して atomic=True が渡されて生成されたトランザクション中においてのみ実行されます。 警告 RunPython はモデルのデータベース接続を魔法のよう ... ... now support incr() and decr() commands to increment and decrement the value of a cache key. On cache backends that support atomic increment/decrement -- most notably, the memcached backend -- these operations will be atomic, and quite fast. Django now ... ... など)、すべての操作はトランザクションなしで実行されます。 マイグレーションをトランザクション内で実行しないようにするには、 atomic 属性を False に設定します。たとえば次のようにします。 from django.db import migrations class Migration ( migrations . Migr ... ation ): atomic = False It's also possible to execute parts of the migration inside a transaction using atomic() or by passing atomic=True ... ... gument to the RunSQL and RunPython operations to allow them to be removed when squashing migrations. Added support for non-atomic migrations by setting the atomic attribute on a Migration . The migrate and makemigrations commands now check for a consis ... Response are now closed immediately instead of when the WSGI server calls close() on the response. A redundant transaction.atomic() call in QuerySet.update_or_create() is removed. This may affect query counts tested by TransactionTestCase.assertNumQuer ... ... eption. This change was made because such errors can be caused by including an app which expects global transactions (e.g. ATOMIC_REQUESTS set to True ), or Django's old autocommit behavior, in a project which runs without them; and further, such error ... voided shadowing deadlock exceptions on MySQL ( #22291 ). Wrapped database exceptions in _set_autocommit ( #22321 ). Fixed atomicity when closing a database connection or when the database server disconnects ( #21239 and #21202 ) Fixed regression in pr ... 2026年10月08日