... えることなく、 model_name で指定したモデルの name という名前の制約を新たな constraint に置き換えます。 特別なオペレーション RunSQL class RunSQL ( sql , reverse_sql = None , state_operations = None , hints = None , elidable = False ) [ソース] データベース ... メータを cursor.execute() において行うのと同じ形式で渡すために用いられます。以下の 3 つの処理は互いに等価です: migrations . RunSQL ( "INSERT INTO musician (name) VALUES ('Reinhardt');" ) migrations . RunSQL ([( "INSERT INTO musician (name) VALUES ('Rein ... hardt');" , None )]) migrations . RunSQL ([( "INSERT INTO musician (name) VALUES ( %s );" , [ "Reinhardt" ])]) クエリにパーセント文字リテラルを含ませたい場合、パラ ... ... migrations ] operations = [ migrations . RunPython ( forwards , hints = { "target_db" : "default" }), ] もし RunPython や RunSQL 操作が 1 つのモデルにしか影響しないのであれば、 model_name をヒントとして渡すことで、ルーターに対して最大限、透過的になりま ... し、すべての行に一意な値を設定するまで、一意制約の作成を延期します。 最初の空のマイグレーションファイルに、 RunPython または RunSQL オペレーションを追加して、既存の各行に対して一意な値 (この例では UUID) を生成します。 uuid のインポートも追加します。例: 0 ... erations = [ # Old table name from checking with sqlmigrate, new table # name from AuthorBook._meta.db_table. migrations . RunSQL ( sql = "ALTER TABLE core_book_authors RENAME TO core_authorbook" , reverse_sql = "ALTER TABLE core_authorbook RENAME TO c ... ... ed to the django.request logger when a middleware raises a MiddlewareNotUsed exception in DEBUG mode. マイグレーション The RunSQL operation can now handle parameters passed to the SQL statements. It is now possible to have migrations (most probably dat ... 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 operati ... ons RunPython and RunSQL now call the allow_migrate() method of database routers. The router can use the newly introduced app_label and hints argum ... ... ケースを追加するのを避けようとします。データベース固有のオプションを使いたければ、あなたが指定したい ALTER TABLE 文を含めた RunSQL を使ったマイグレーションを作成してください。 たとえば、 MySQL を使っていて、 MyISAM ストレージエンジンを使いたい場合、以下 ... ... ). Added the get_extra() , get_max_num() , and get_min_num() hooks to GenericInlineModelAdmin ( #23539 ). Made migrations.RunSQL no longer require percent sign escaping. This is now consistent with cursor.execute() ( #23426 ). TEST 辞書の SERIALIZE 項 ... ... for cyclic dependencies much more helpful. Added missing index_together handling for SQLite ( #23880 ). Fixed a crash when RunSQL SQL content was collected by the schema editor, typically when using sqlmigrate ( #23909 ). Fixed a regression in contrib. ... ... pplying books.0003_auto...Traceback (most recent call last): django.db.migrations.exceptions.IrreversibleError: Operation <RunSQL sql='DROP TABLE demo_books'> in books.0003_auto is not reversible ...\> py manage.py migrate books 0002 Operations to perf ... pplying books.0003_auto...Traceback (most recent call last): django.db.migrations.exceptions.IrreversibleError: Operation <RunSQL sql='DROP TABLE demo_books'> in books.0003_auto is not reversible 履歴上のモデル マイグレーションを実行するとき、 Django は ... らしたら (どれだけ減らせるかは、モデルがどれだけ密接に絡み合っているか、また elidable とマークされていない限り最適化できない RunSQL や RunPython 操作があるかどうかによって決まります)、Django はそれを新しいマイグレーションファイル群に書き戻します。 These ... ... 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 migrations; in par ... がインストールされている場合、初期 SQL データがより良く動作するようになりました。 Note that it's deprecated in favor of the RunSQL operation of migrations, which benefits from the improved behavior. モデル The QuerySet.update_or_create() method was adde ... ... る必要があります: ALTER TABLE ` your_table ` MODIFY ` your_datetime_column ` DATETIME ( 6 ) または データマイグレーション の RunSQL オペレーションを使用します。 TIMESTAMP カラム もし TIMESTAMP カラムを含むレガシーデータベースを使用している場合、データの破 ... ... es as arguments. マイグレーション 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 ... 2026年10月08日