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
80%Fix Rate
81%Confidence
0Evidence
2024-08-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.2 | active | — | — | — |
| 4.0 | active | — | — | — |
Root Cause
迁移表已存在但迁移历史不一致,通常由迁移冲突引起
generic中文
数据库中存在 django_migrations 表,但迁移状态与文件不匹配
Workarounds
-
90% success 使用 --fake 标记已应用的迁移
python manage.py migrate --fake
-
85% success 回滚并重新迁移
python manage.py migrate app_name zero && python manage.py migrate app_name
Dead Ends
Common approaches that don't work:
-
删除 django_migrations 表
90% fail
导致迁移历史丢失,无法追踪已应用的迁移
-
手动修改迁移表记录
80% fail
可能引入不一致,导致后续迁移失败