... フォルトのマイグレーションは既存のテーブルを削除して新しいテーブルを作成し、既存のリレーションを失います。これを避けるには、 SeparateDatabaseAndState を使用して、マイグレーションの自動検出器に新しいモデルが作成されたことを伝えながら、既存のテーブル名を新しいテーブル名に変 ... 確認できます。新しい through モデルは ForeignKey に Django と同じ名前を使うべきです。また、追加のフィールドが必要な場合は、 SeparateDatabaseAndState の後の操作で追加してください。 例えば、 Author にリンクする ManyToManyField を持つ Book モデルがあった場合、次のように新し ... on class Migration ( migrations . Migration ): dependencies = [ ( "core" , "0001_initial" ), ] operations = [ migrations . SeparateDatabaseAndState ( database_operations = [ # Old table name from checking with sqlmigrate, new table # name from AuthorBook._meta.db_table. ... ... する場合は Django のモデル機構のスコープ範囲外 (たとえば triggers など) で行うか、もしくはモデルの状態に変更を反映する処理に SeparateDatabaseAndState を追加する事を心がけてください。そうでなければ、バージョン管理された ORM およびマイグレーションの自動検出機構が正常に動作し ... code もしくは reverse_code に RunPython.noop メソッドを渡してください。この指定は処理を逆順で行いたい場合に特に有用です。 SeparateDatabaseAndState class SeparateDatabaseAndState ( database_operations = None , state_operations = None ) [ソース] データベース(スキーマ変更 ... hell を使うことができます。状態のオペレーションをチェックするために makemigrations 、特に --dry-run を使うことができます。 SeparateDatabaseAndState の使用例は、 ManyToManyField を中間 (through) モデルを使うように変更する を参照してください。 オペレーション・カテゴリ cla ... ... mats.py with django.utils.formats.get_format() and the date template filter ( #25812 ). Fixed a state bug when migrating a SeparateDatabaseAndState operation backwards ( #25896 ). Fixed missing varchar/text_pattern_ops index on CharField and TextField respectively when ... ... tion with two operations: RemoveConstraint and AddConstraint . Since this change has no effect on the database schema, the SeparateDatabaseAndState operation can be used to only update the migration state without running any SQL. Move the generated operations into the s ... tate_operations argument of SeparateDatabaseAndState . For example: class Migration ( migrations . Migration ): ... operations = [ migrations . SeparateDatabaseAndState ( data ... ... language() and get_language_bidi() when translations are deactivated ( #24569 ). Fixed squashmigrations command when using SeparateDatabaseAndState ( #24278 ). Stripped microseconds from datetime values when using an older version of the MySQLdb DB API driver as it does ... ... ce ( #25548 , #26018 ). Fixed a system check crash with nested ArrayField s ( #25867 ). Fixed a state bug when migrating a SeparateDatabaseAndState operation backwards ( #25896 ). Fixed a regression in CommonMiddleware causing If-None-Match checks to always return HTTP ... ... します。 エラーを避けるために、上記のようなマイグレーションは --fake オプションを付けて適用することを推奨します。 代わりに、 SeparateDatabaseAndState を使うことで、データベース固有のマイグレーションと Django による状態管理用マイグレーションを、1つの操作としてまとめて実行す ... 2026年10月08日