python data_error ai_generated partial

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

ID: python/django-migration-irreversible

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-06-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. Forcing reverse migration with --fake 80% fail

    May leave database in inconsistent state.

  2. Deleting migration files 70% fail

    Breaks migration chain; may cause future errors.