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
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.
解决方案
-
90% 成功率 Add reverse code to RunSQL operations
migrations.RunSQL(sql, reverse_sql='DROP TABLE ...')
-
85% 成功率 Create a new migration to revert changes
Generate a new migration that reverses the effects.
无效尝试
常见但无效的做法:
-
Forcing reverse migration with --fake
80% 失败
May leave database in inconsistent state.
-
Deleting migration files
70% 失败
Breaks migration chain; may cause future errors.