... する必要があるかもしれません。例えば、特定のデータベースに対してのみマイグレーションを実行したい場合です。 これを行うには、 RunPython 操作の中で、 schema_editor.connection.alias 属性を見て、データベース接続のエイリアスを確認します: from django.db import mi ... ss Migration ( migrations . Migration ): dependencies = [ # Dependencies to other migrations ] operations = [ migrations . RunPython ( forwards ), ] You can also provide hints that will be passed to the allow_migrate() method of database routers as **hint ... ss Migration ( migrations . Migration ): dependencies = [ # Dependencies to other migrations ] operations = [ migrations . RunPython ( forwards , hints = { "target_db" : "default" }), ] もし RunPython や RunSQL 操作が 1 つのモデルにしか影響しないのであれば ... ... する必要があるかもしれません。例えば、特定のデータベースに対してのみマイグレーションを実行したい場合です。 これを行うには、 RunPython 操作の中で、 schema_editor.connection.alias 属性を見て、データベース接続のエイリアスを確認します: from django.db import mi ... ss Migration ( migrations . Migration ): dependencies = [ # Dependencies to other migrations ] operations = [ migrations . RunPython ( forwards ), ] You can also provide hints that will be passed to the allow_migrate() method of database routers as **hint ... ss Migration ( migrations . Migration ): dependencies = [ # Dependencies to other migrations ] operations = [ migrations . RunPython ( forwards , hints = { "target_db" : "default" }), ] もし RunPython や RunSQL 操作が 1 つのモデルにしか影響しないのであれば ... ... erbose_name のような雑多なモデルオプション(モデルの Meta の設定)の変更を保存します。データベースには影響を与えませんが、 RunPython インスタンスが使用するためにこれらの変更を保持します。 options はオプション名と値をマッピングした辞書である必要があります。 ... ない場合、 sql もしくは reverse_sql に対して RunSQL.noop 要素を渡します。これは特に処理を逆の順序で行いたい場合に有用です。 RunPython ¶ class RunPython ( code , reverse_code = None , atomic = None , hints = None , elidable = False ) [ソース] ¶ マイグレーシ ... 、先の呼び出し可能オブジェクト code で行われた処理を無効化しなければなりません。 reverse_code が None (デフォルト) の場合、 RunPython オペレーションは元に戻りません。 オプションの hints 引数はルーティングの決定を補助するためにデータベースルータの allow_mig ... ... erbose_name のような雑多なモデルオプション(モデルの Meta の設定)の変更を保存します。データベースには影響を与えませんが、 RunPython インスタンスが使用するためにこれらの変更を保持します。 options はオプション名と値をマッピングした辞書である必要があります。 ... ない場合、 sql もしくは reverse_sql に対して RunSQL.noop 要素を渡します。これは特に処理を逆の順序で行いたい場合に有用です。 RunPython ¶ class RunPython ( code , reverse_code = None , atomic = None , hints = None , elidable = False ) [ソース] ¶ マイグレーシ ... 、先の呼び出し可能オブジェクト code で行われた処理を無効化しなければなりません。 reverse_code が None (デフォルト) の場合、 RunPython オペレーションは元に戻りません。 オプションの hints 引数はルーティングの決定を補助するためにデータベースルータの allow_mig ... ... alse It's also possible to execute parts of the migration inside a transaction using atomic() or by passing atomic=True to RunPython . See 非アトミックのマイグレーション for more details. 依存関係 ¶ マイグレーションはアプリごとに作られますが、モデルが表し ... rgs のような一文を追加してください。 モデルマネージャ ¶ オプションとして、マネージャをマイグレーションにシリアライズして、 RunPython の中で使えるようにすることができます。それには次のように、マネージャクラスの中で use_in_migrations 属性を定義します。 clas ... マイグレーションを実行するとき、 Django はマイグレーションファイルに保存されたモデルの過去のバージョンから作業しています。 RunPython オペレーションを使って Python コードを書いたり、データベースルーターに allow_migrate メソッドがある場合、 直接インポートす ... ... alse It's also possible to execute parts of the migration inside a transaction using atomic() or by passing atomic=True to RunPython . See 非アトミックのマイグレーション for more details. 依存関係 ¶ マイグレーションはアプリごとに作られますが、モデルが表し ... rgs のような一文を追加してください。 モデルマネージャ ¶ オプションとして、マネージャをマイグレーションにシリアライズして、 RunPython の中で使えるようにすることができます。それには次のように、マネージャクラスの中で use_in_migrations 属性を定義します。 clas ... マイグレーションを実行するとき、 Django はマイグレーションファイルに保存されたモデルの過去のバージョンから作業しています。 RunPython オペレーションを使って Python コードを書いたり、データベースルーターに allow_migrate メソッドがある場合、 直接インポートす ... ... if the right or left hand side of an expression is a key transform ( #30826 ). Prevented migrate --plan from showing that RunPython operations are irreversible when reverse_code callables don't have docstrings or when showing a forward migration plan ( # ... ... if the right or left hand side of an expression is a key transform ( #30826 ). Prevented migrate --plan from showing that RunPython operations are irreversible when reverse_code callables don't have docstrings or when showing a forward migration plan ( # ... ... ze model managers as part of the model state. A generic mechanism to handle the deprecation of model fields was added. The RunPython.noop() and RunSQL.noop class method/attribute were added to ease in making RunPython and RunSQL operations reversible. The ... migration operations RunPython and RunSQL now call the allow_migrate() method of database routers. The router can use the newly introduced app_label and ... de the hints dictionary under the key 'model' . After switching to the new signature the router will also be called by the RunPython and RunSQL operations. Features removed in 1.8 ¶ These features have reached the end of their deprecation cycle and are re ... ... ze model managers as part of the model state. A generic mechanism to handle the deprecation of model fields was added. The RunPython.noop() and RunSQL.noop class method/attribute were added to ease in making RunPython and RunSQL operations reversible. The ... migration operations RunPython and RunSQL now call the allow_migrate() method of database routers. The router can use the newly introduced app_label and ... de the hints dictionary under the key 'model' . After switching to the new signature the router will also be called by the RunPython and RunSQL operations. Features removed in 1.8 ¶ These features have reached the end of their deprecation cycle and are re ... 2026年10月08日