python module_error ai_generated true

配置错误:导入迁移模块 django.contrib.admin.migrations 失败:找不到模块 'django.contrib.admin.migrations'

django.core.exceptions.ImproperlyConfigured: Error importing migration module django.contrib.admin.migrations: No module named 'django.contrib.admin.migrations'

ID: python/django-missing-migrations-dir

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

版本兼容性

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

根因分析

迁移包目录缺失或损坏,通常由于安装不完整或手动删除导致。

English

The migrations package directory is missing or corrupted, often due to incomplete installation or manual deletion.

generic

解决方案

  1. 70% 成功率
    Reinstall Django: pip install --force-reinstall Django==3.2.0
  2. 90% 成功率
    Create empty __init__.py in each app's migrations directory, then run makemigrations --empty appname

无效尝试

常见但无效的做法:

  1. 80% 失败

    Running migrate again won't recreate missing migration files; it only applies existing migrations.

  2. 60% 失败

    Deleting and recreating the migrations folder manually can cause inconsistency with the database migration history.