django-migrations

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Django migrations

Django 迁移

Read these files first, before writing or editing a migration:
  • docs/published/handbook/engineering/developing-locally.md
    (
    ## Django migrations
    ,
    ### Non-blocking migrations
    ,
    ### Resolving merge conflicts
    )
  • docs/published/handbook/engineering/safe-django-migrations.md
  • docs/published/handbook/engineering/databases/schema-changes.md
  • products/README.md
    (
    ## Adding or moving backend models and migrations
    ) when working in
    products/*
If the task is a ClickHouse migration, use
clickhouse-migrations
instead.
在编写或编辑迁移之前,请先阅读以下文件:
  • docs/published/handbook/engineering/developing-locally.md
    ## Django 迁移
    ### 非阻塞迁移
    ### 解决合并冲突
    章节)
  • docs/published/handbook/engineering/safe-django-migrations.md
  • docs/published/handbook/engineering/databases/schema-changes.md
  • 若在
    products/*
    目录下工作,请阅读
    products/README.md
    ## 添加或迁移后端模型与迁移文件
    章节)
若任务涉及ClickHouse迁移,请改用
clickhouse-migrations

Workflow

工作流

  1. Classify the change as additive (new nullable column, new table) or risky (drop/rename,
    NOT NULL
    , indexes, constraints, large data updates, model moves).
  2. Generate:
    DEBUG=1 ./manage.py makemigrations [app_label]
    . For merge conflicts:
    python manage.py rebase_migration <app> && git add <app>/migrations
    (
    posthog
    or
    ee
    ).
  3. Apply safety rules from
    safe-django-migrations.md
    — the doc covers multi-phase rollouts,
    SeparateDatabaseAndState
    , concurrent operations, idempotency, and all risky patterns in detail.
  4. Validate:
    ./manage.py sqlmigrate <app> <migration_number>
    , run tests, confirm linear migration sequence.
  1. 分类变更类型:分为新增类(如新的可空列、新表)或风险类(如删除/重命名、
    NOT NULL
    约束、索引、约束、大规模数据更新、模型迁移)。
  2. 生成迁移文件:执行
    DEBUG=1 ./manage.py makemigrations [app_label]
    。 若存在合并冲突:执行
    python manage.py rebase_migration <app> && git add <app>/migrations
    <app>
    posthog
    ee
    )。
  3. 应用安全规则:遵循
    safe-django-migrations.md
    中的规范——该文档详细介绍了多阶段发布、
    SeparateDatabaseAndState
    、并发操作、幂等性以及所有风险操作模式。
  4. 验证:执行
    ./manage.py sqlmigrate <app> <migration_number>
    ,运行测试,确认迁移序列的线性顺序。