... する必要があるかもしれません。例えば、特定のデータベースに対してのみマイグレーションを実行したい場合です。 これを行うには、 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 ... ... 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. 依存関係 マイグレーションはアプリごとに作られますが、モデルが表して ... wargs のような一文を追加してください。 モデルマネージャ オプションとして、マネージャをマイグレーションにシリアライズして、 RunPython の中で使えるようにすることができます。それには次のように、マネージャクラスの中で use_in_migrations 属性を定義します。 clas ... マイグレーションを実行するとき、 Django はマイグレーションファイルに保存されたモデルの過去のバージョンから作業しています。 RunPython オペレーションを使って Python コードを書いたり、データベースルーターに allow_migrate メソッドがある場合、 直接インポートす ... ... he 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 remo ... ... grations; if you want to load initial data for an app, we suggest you create a migration for your application and define a RunPython or RunSQL operation in the operations section of the migration. Test rollback behavior is different for apps with migratio ... apps will not have this support. Instead, you are encouraged to load initial data in migrations if you need it (using the RunPython operation and your model classes); this has the added advantage that your initial data will not need updating every time y ... ... .backends.schema スキーマの変更中に実行されるSQLクエリを、 マイグレーションフレームワーク によってログ記録します。ただし、 RunPython によって実行されるクエリはログされません。このロガーへのメッセージには、 params と sql が追加のコンテキストとして含まれます ... ... ents. マイグレーション Added support for serialization of enum.Enum objects. Added the elidable argument to the RunSQL and RunPython operations to allow them to be removed when squashing migrations. Added support for non-atomic migrations by setting the a ... ... マイグレーション適用のスピードを改善するため、処理が必要とするまで関連モデルのレンダリングを送らせるようになりました (例: RunPython )。 database_forwards() や database_backwards() の from_state 引数からモデルクラスやモデルインスタンスを操作するような独自 ... ... # replace this with the latest migration in contrib.auth ( "auth" , "####_migration_name" ), ] operations = [ migrations . RunPython ( forwards_func ), ] このマイグレーションには、ハードウェアの速度にもよりますが、数千人のユーザーで数分かかることに注意して ... 2026年10月08日