[Django]-Django No module named 'django.db.migrations.migration'

39👍

Your Django installation seems corrupted. You can reinstall with:

pip3 uninstall Django
pip3 install Django

Usually this happens if you installed Django in your regular operating system’s python installation and then later installed a virtualenv copy and tried to run the django server. You need to reinstall Django in your virtualenv, after removing it first if it already exists.

11👍

Assuming you are running in the virtual environment, you might have actually deleted the files under /django/db/migrations/ as well. So the error is obvious here. You would need to reinstall django to get the files back for successful migration.

To do this, check the django version

python -m django --version

Then install the same version using following command

pip install --upgrade --force-reinstall  Django==3.2.2
👤s4n7h0

4👍

Without thinking I copy-pasted and run this oneliner in the root directory.

find . -path "*/migrations/*.py" -not -name "__init__.py" -delete

Well, I had Django installed within the venv, and – surprise surprise – there’s a migrations package in the Django source code.
After reinstall everything works fine.

Leave a comment