python data_error ai_generated partial

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (already exists)

ID: python/django-migration-conflict

Also available as: JSON · Markdown · 中文
80%Fix Rate
81%Confidence
0Evidence
2024-08-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.2 active
4.0 active

Root Cause

迁移表已存在但迁移历史不一致,通常由迁移冲突引起

generic

中文

数据库中存在 django_migrations 表,但迁移状态与文件不匹配

Workarounds

  1. 90% success 使用 --fake 标记已应用的迁移
    python manage.py migrate --fake
  2. 85% success 回滚并重新迁移
    python manage.py migrate app_name zero && python manage.py migrate app_name

Dead Ends

Common approaches that don't work:

  1. 删除 django_migrations 表 90% fail

    导致迁移历史丢失,无法追踪已应用的迁移

  2. 手动修改迁移表记录 80% fail

    可能引入不一致,导致后续迁移失败