Django 6.1.3 on SQLite (in-memory): ch09-database 1. ConnectionHandler laziness, request signals, and DatabaseErrorWrapper before_query: connection_is_none=True autocommit=False CONN_MAX_AGE=0 CONN_HEALTH_CHECKS=False after_ensure_connection: connection_is_none=False close_at_is_set=True health_check_done=True request_started_db_receivers = ['django.db.reset_queries', 'django.db.close_old_connections'] request_finished_db_receivers = ['django.db.close_old_connections'] errors_occurred: after_IntegrityError=False after_OperationalError=True 2. Cross-backend DatabaseFeatures divergence in Django 6.1.3 feature sqlite3 postgres mysql oracle can_rollback_ddl True True False False has_select_for_update False True True True can_return_rows_from_bulk_insert True True dynamic False supports_timezones False True False False supports_logical_xor False False True False interprets_empty_strings_as_nulls False False False True supports_on_delete_db_default True True False False 3. Autocommit, nested atomic() savepoints, needs_rollback, and durable=True nested_savepoint_sql: BEGIN INSERT INTO "newsroom_desk" ("name", "slug", "section_code") VALUES (%s, %s, %s) RETURNING "newsroom_desk"."id" SAVEPOINT "s_x1" INSERT INTO "newsroom_desk" ("name", "slug", "section_code") VALUES (%s, %s, %s) RETURNING "newsroom_desk"."id" ROLLBACK TO SAVEPOINT "s_x1" RELEASE SAVEPOINT "s_x1" after_nested_atomic: science_exists=True temp_exists=False poisoned_block: needs_rollback=True poisoned_next_query = TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block. nested_durable_error = RuntimeError: A durable atomic block cannot be nested within another atomic block. 4. transaction.on_commit ordering, savepoint discard, and robust=True autocommit_on_commit = ['autocommit-immediate'] queued_hooks: inside_inner=2 after_savepoint_rollback=1 fired_before_commit=[] fired_after_outer_commit = ['outer-before', 'outer-after'] robust_hooks = ['hook-1-runs-and-raises', 'hook-2-still-runs'] 5. MigrationGraph, MigrationLoader, and ProjectState historical models loader: disk_migrations=20 applied_migrations=20 leaf_apps=['admin', 'auth', 'contenttypes', 'newsroom', 'sessions', 'subscribers'] forwards_plan_subscribers = [('contenttypes', '0001_initial'), ('auth', '0001_initial'), ('newsroom', '0001_initial'), ('subscribers', '0001_initial')] live_Story: module='newsroom.models' has_published=True str='Bridge bond passes council' hist_Story: module='__fake__' is_live=False has_published=False str='Story object (1)' 6. MigrationAutodetector diffing ProjectState and MigrationOptimizer detected_apps = ['newsroom'] migration='0002_story_byline_alter_story_headline' dependencies=[('newsroom', '0001_initial')] op = Add field byline to story op = Alter field headline on story optimizer_merge: 3 ops -> 1 op (CreateModel fields=['id', 'level']) optimizer_cancel: Create+Delete -> 0 ops; with RunSQL barrier -> 3 ops 7. BaseDatabaseSchemaEditor: SQLite ADD COLUMN vs _remake_table sqlite_add_nullable_field (1 statements): ALTER TABLE "newsroom_story" ADD COLUMN "kicker" varchar(80) NULL; sqlite_alter_field_remake_table (7 statements): CREATE TABLE "new__newsroom_story" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "headline" varchar(200) NOT NULL, "slug" varchar(160) NOT NULL UNIQUE, "body" text NOT NULL, "priority" smallint unsigned NOT NULL CHECK ("priority" >= 0), "status" varchar(16) NOT NULL, "published_at" datetime NULL, "desk_id" bigint NOT NULL REFERENCES "newsroom_desk" ("id") DEFERRABLE INITIALLY DEFERRED, "reporter_id" bigint NOT NULL REFERENCES "newsroom_reporter" ("id") DEFERRABLE INITIALLY DEFERRED, "edition_id" bigint NOT NULL REFERENCES "newsroom_edition" ("id") DEFERRABLE INITIALLY DEFERRED); INSERT INTO "new__newsroom_story" ("id", "slug", "body", "priority", "status", "published_at", "desk_id", "reporter_id", "edition_id", "headline") SELECT "id", "slug", "body", "priority", "status", "published_at", "desk_id", "reporter_id", "edition_id", "headline" FROM "newsroom_story"; DROP TABLE "newsroom_story"; ALTER TABLE "new__newsroom_story" RENAME TO "newsroom_story"; CREATE INDEX "newsroom_story_desk_id_e230087a" ON "newsroom_story" ("desk_id"); CREATE INDEX "newsroom_story_reporter_id_ef8ca261" ON "newsroom_story" ("reporter_id"); CREATE INDEX "newsroom_story_edition_id_b9299bd3" ON "newsroom_story" ("edition_id"); django_migrations_desk_rows = ['newsroom.0001_initial', 'subscribers.0001_initial']