« ^ »
[WIP]

Djangoのマイグレーションファイルをまとめる

所要時間: 約 8分

準備

PostgreSQLを使う。

CREATE DATABASE example;
pip install psycopg2-binary
ALTER ROLE postgres SET log_statement = 'all',
ALTER USER postgres SET log_statement to 'all';

全て消してmakemigrations

  • 本番のデータベースがまだ無い場合はできる。既に本番のデータベースがある場合はできない。
  • マイグレーションファイルをすべて消して、makemigrationsしなおす。

squashmigrationする

–fake-initialする

2022-12-23 04:00:27.254 UTC [558] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:00:27.262 UTC [558] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:00:27.265 UTC [558] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:00:27.269 UTC [558] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:00:27.277 UTC [558] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:00:27.281 UTC [558] LOG:  statement: BEGIN
2022-12-23 04:00:27.282 UTC [558] LOG:  statement: CREATE TABLE "app_fake_initial_foo" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)
2022-12-23 04:00:27.289 UTC [558] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:00:27.294 UTC [558] LOG:  statement: INSERT INTO "django_migrations" ("app", "name", "applied") VALUES ('app_fake_initial', '0001_initial', '2022-12-23T04:00:27.275055+00:00'::timestamptz) RETURNING "django_migrations"."id"
2022-12-23 04:00:27.296 UTC [558] LOG:  statement: COMMIT
2022-12-23 04:00:27.299 UTC [558] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:00:27.302 UTC [558] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:00:27.305 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:00:27.309 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'admin' AND "django_content_type"."model" = 'logentry') LIMIT 21
2022-12-23 04:00:27.312 UTC [558] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (1) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:00:27.315 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:00:27.318 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:00:27.321 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'permission') LIMIT 21
2022-12-23 04:00:27.323 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'group') LIMIT 21
2022-12-23 04:00:27.326 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'user') LIMIT 21
2022-12-23 04:00:27.329 UTC [558] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (2, 3, 4) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:00:27.332 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:00:27.335 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:00:27.337 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'contenttypes' AND "django_content_type"."model" = 'contenttype') LIMIT 21
2022-12-23 04:00:27.340 UTC [558] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (5) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:00:27.343 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:00:27.345 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:00:27.348 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'sessions' AND "django_content_type"."model" = 'session') LIMIT 21
2022-12-23 04:00:27.352 UTC [558] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (6) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:00:27.354 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:00:27.357 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'
2022-12-23 04:00:27.359 UTC [558] LOG:  statement: BEGIN
2022-12-23 04:00:27.360 UTC [558] LOG:  statement: INSERT INTO "django_content_type" ("app_label", "model") VALUES ('app_fake_initial', 'foo') RETURNING "django_content_type"."id"
2022-12-23 04:00:27.362 UTC [558] LOG:  statement: COMMIT
2022-12-23 04:00:27.365 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'foo') LIMIT 21
2022-12-23 04:00:27.368 UTC [558] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (7) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:00:27.370 UTC [558] LOG:  statement: BEGIN
2022-12-23 04:00:27.372 UTC [558] LOG:  statement: INSERT INTO "auth_permission" ("name", "content_type_id", "codename") VALUES ('Can add foo', 7, 'add_foo'), ('Can change foo', 7, 'change_foo'), ('Can delete foo', 7, 'delete_foo'), ('Can view foo', 7, 'view_foo') RETURNING "auth_permission"."id"
2022-12-23 04:00:27.375 UTC [558] LOG:  statement: COMMIT
2022-12-23 04:00:27.379 UTC [558] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'

Barを追加する

2022-12-23 04:11:18.501 UTC [592] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:11:18.509 UTC [592] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:11:18.512 UTC [592] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:11:18.517 UTC [592] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:11:18.527 UTC [592] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:11:18.531 UTC [592] LOG:  statement: BEGIN
2022-12-23 04:11:18.532 UTC [592] LOG:  statement: CREATE TABLE "app_fake_initial_bar" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)
2022-12-23 04:11:18.541 UTC [592] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:11:18.544 UTC [592] LOG:  statement: INSERT INTO "django_migrations" ("app", "name", "applied") VALUES ('app_fake_initial', '0002_bar', '2022-12-23T04:11:18.531086+00:00'::timestamptz) RETURNING "django_migrations"."id"
2022-12-23 04:11:18.546 UTC [592] LOG:  statement: COMMIT
2022-12-23 04:11:18.548 UTC [592] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:11:18.551 UTC [592] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:11:18.554 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:11:18.557 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'admin' AND "django_content_type"."model" = 'logentry') LIMIT 21
2022-12-23 04:11:18.561 UTC [592] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (1) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:11:18.565 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:11:18.567 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:11:18.570 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'permission') LIMIT 21
2022-12-23 04:11:18.573 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'group') LIMIT 21
2022-12-23 04:11:18.576 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'user') LIMIT 21
2022-12-23 04:11:18.580 UTC [592] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (2, 3, 4) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:11:18.583 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:11:18.586 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:11:18.589 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'contenttypes' AND "django_content_type"."model" = 'contenttype') LIMIT 21
2022-12-23 04:11:18.592 UTC [592] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (5) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:11:18.595 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:11:18.598 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:11:18.601 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'sessions' AND "django_content_type"."model" = 'session') LIMIT 21
2022-12-23 04:11:18.605 UTC [592] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (6) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:11:18.608 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:11:18.611 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'
2022-12-23 04:11:18.613 UTC [592] LOG:  statement: BEGIN
2022-12-23 04:11:18.615 UTC [592] LOG:  statement: INSERT INTO "django_content_type" ("app_label", "model") VALUES ('app_fake_initial', 'bar') RETURNING "django_content_type"."id"
2022-12-23 04:11:18.617 UTC [592] LOG:  statement: COMMIT
2022-12-23 04:11:18.621 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'foo') LIMIT 21
2022-12-23 04:11:18.625 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'bar') LIMIT 21
2022-12-23 04:11:18.629 UTC [592] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (8, 7) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:11:18.633 UTC [592] LOG:  statement: BEGIN
2022-12-23 04:11:18.634 UTC [592] LOG:  statement: INSERT INTO "auth_permission" ("name", "content_type_id", "codename") VALUES ('Can add bar', 8, 'add_bar'), ('Can change bar', 8, 'change_bar'), ('Can delete bar', 8, 'delete_bar'), ('Can view bar', 8, 'view_bar') RETURNING "auth_permission"."id"
2022-12-23 04:11:18.637 UTC [592] LOG:  statement: COMMIT
2022-12-23 04:11:18.641 UTC [592] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'

migrate –fake-initial

2022-12-23 04:12:28.587 UTC [598] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:12:28.595 UTC [598] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:12:28.599 UTC [598] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:12:28.602 UTC [598] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:12:28.615 UTC [598] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:12:28.618 UTC [598] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:12:28.621 UTC [598] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:12:28.624 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:12:28.628 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'admin' AND "django_content_type"."model" = 'logentry') LIMIT 21
2022-12-23 04:12:28.632 UTC [598] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (1) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:12:28.636 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:12:28.639 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:12:28.641 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'permission') LIMIT 21
2022-12-23 04:12:28.644 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'group') LIMIT 21
2022-12-23 04:12:28.647 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'user') LIMIT 21
2022-12-23 04:12:28.650 UTC [598] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (2, 3, 4) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:12:28.654 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:12:28.657 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:12:28.660 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'contenttypes' AND "django_content_type"."model" = 'contenttype') LIMIT 21
2022-12-23 04:12:28.663 UTC [598] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (5) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:12:28.665 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:12:28.668 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:12:28.671 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'sessions' AND "django_content_type"."model" = 'session') LIMIT 21
2022-12-23 04:12:28.674 UTC [598] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (6) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:12:28.676 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:12:28.679 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'
2022-12-23 04:12:28.682 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'bar') LIMIT 21
2022-12-23 04:12:28.685 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'foo') LIMIT 21
2022-12-23 04:12:28.688 UTC [598] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (8, 7) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:12:28.691 UTC [598] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'

新たなマイグレーションファイルを追加しmanage.py migrate。

2022-12-23 04:15:08.037 UTC [612] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:15:08.047 UTC [612] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:15:08.050 UTC [612] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:15:08.054 UTC [612] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:15:08.064 UTC [612] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:15:08.068 UTC [612] LOG:  statement: BEGIN
2022-12-23 04:15:08.069 UTC [612] LOG:  statement: CREATE TABLE "app_fake_initial_baz" ("id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY)
2022-12-23 04:15:08.075 UTC [612] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:15:08.078 UTC [612] LOG:  statement: INSERT INTO "django_migrations" ("app", "name", "applied") VALUES ('app_fake_initial', '0002_baz', '2022-12-23T04:15:08.072517+00:00'::timestamptz) RETURNING "django_migrations"."id"
2022-12-23 04:15:08.080 UTC [612] LOG:  statement: COMMIT
2022-12-23 04:15:08.083 UTC [612] LOG:  statement: 
                    SELECT
                        c.relname,
                        CASE
                            WHEN c.relispartition THEN 'p'
                            WHEN c.relkind IN ('m', 'v') THEN 'v'
                            ELSE 't'
                        END
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
                
2022-12-23 04:15:08.086 UTC [612] LOG:  statement: SELECT "django_migrations"."id", "django_migrations"."app", "django_migrations"."name", "django_migrations"."applied" FROM "django_migrations"
2022-12-23 04:15:08.089 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:15:08.092 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'admin' AND "django_content_type"."model" = 'logentry') LIMIT 21
2022-12-23 04:15:08.096 UTC [612] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (1) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:15:08.099 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'admin'
2022-12-23 04:15:08.102 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:15:08.104 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'permission') LIMIT 21
2022-12-23 04:15:08.107 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'group') LIMIT 21
2022-12-23 04:15:08.110 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'auth' AND "django_content_type"."model" = 'user') LIMIT 21
2022-12-23 04:15:08.113 UTC [612] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (2, 3, 4) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:15:08.116 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'auth'
2022-12-23 04:15:08.118 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:15:08.120 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'contenttypes' AND "django_content_type"."model" = 'contenttype') LIMIT 21
2022-12-23 04:15:08.123 UTC [612] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (5) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:15:08.126 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'contenttypes'
2022-12-23 04:15:08.128 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:15:08.131 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'sessions' AND "django_content_type"."model" = 'session') LIMIT 21
2022-12-23 04:15:08.134 UTC [612] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (6) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:15:08.137 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'sessions'
2022-12-23 04:15:08.139 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'
2022-12-23 04:15:08.142 UTC [612] LOG:  statement: BEGIN
2022-12-23 04:15:08.143 UTC [612] LOG:  statement: INSERT INTO "django_content_type" ("app_label", "model") VALUES ('app_fake_initial', 'baz') RETURNING "django_content_type"."id"
2022-12-23 04:15:08.145 UTC [612] LOG:  statement: COMMIT
2022-12-23 04:15:08.148 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'bar') LIMIT 21
2022-12-23 04:15:08.151 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'foo') LIMIT 21
2022-12-23 04:15:08.153 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."app_label" = 'app_fake_initial' AND "django_content_type"."model" = 'baz') LIMIT 21
2022-12-23 04:15:08.156 UTC [612] LOG:  statement: SELECT "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_permission"."content_type_id" IN (8, 9, 7) ORDER BY "django_content_type"."app_label" ASC, "django_content_type"."model" ASC, "auth_permission"."codename" ASC
2022-12-23 04:15:08.160 UTC [612] LOG:  statement: BEGIN
2022-12-23 04:15:08.161 UTC [612] LOG:  statement: INSERT INTO "auth_permission" ("name", "content_type_id", "codename") VALUES ('Can add baz', 9, 'add_baz'), ('Can change baz', 9, 'change_baz'), ('Can delete baz', 9, 'delete_baz'), ('Can view baz', 9, 'view_baz') RETURNING "auth_permission"."id"
2022-12-23 04:15:08.165 UTC [612] LOG:  statement: COMMIT
2022-12-23 04:15:08.169 UTC [612] LOG:  statement: SELECT "django_content_type"."id", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE "django_content_type"."app_label" = 'app_fake_initial'

https://docs.djangoproject.com/en/4.1/ref/django-admin/#cmdoption-migrate-fake-initial

どうやら --fake-initial は初回のマイグレーションをスキップする挙動になるようだ。ドキュメントを見ると、そのように読める。 実際にSQLでも何も更新している痕跡は見えない。本当にそのような実装になっているのかは、コードを追って確認する必要がありそうだ。

    def apply_migration(self, state, migration, fake=False, fake_initial=False):
        """Run a migration forwards."""
        migration_recorded = False
        if self.progress_callback:
            self.progress_callback("apply_start", migration, fake)
        if not fake:
            if fake_initial:
            # Test to see if this is an already-applied initial migration
                applied, state = self.detect_soft_applied(state, migration)
                if applied:
                    fake = True
            if not fake:
                # Alright, do it normally
                with self.connection.schema_editor(atomic=migration.atomic) as schema_editor:
                    state = migration.apply(state, schema_editor)
                    if not schema_editor.deferred_sql:
                        self.record_migration(migration)
                        migration_recorded = True
        if not migration_recorded:
            self.record_migration(migration)
        # Report progress
        if self.progress_callback:
            self.progress_callback("apply_success", migration, fake)
        return state
lib/python3.10/site-packages/django/db/migrations/executor.py

直接書き換える