python data_error ai_generated partial

Django迁移不可逆错误:迁移0002_auto无法回滚

django.db.migrations.exceptions.IrreversibleError: Migration 0002_auto cannot be reversed

ID: python/django-migration-irreversible

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2024-06-10首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

迁移包含不可逆的操作,例如没有反向代码的RunSQL。

English

A migration contains operations that are not reversible, such as RunSQL without reverse code.

generic

解决方案

  1. 90% 成功率 Add reverse code to RunSQL operations
    migrations.RunSQL(sql, reverse_sql='DROP TABLE ...')
  2. 85% 成功率 Create a new migration to revert changes
    Generate a new migration that reverses the effects.

无效尝试

常见但无效的做法:

  1. Forcing reverse migration with --fake 80% 失败

    May leave database in inconsistent state.

  2. Deleting migration files 70% 失败

    Breaks migration chain; may cause future errors.