Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django No module named 'django.db.migrations.migration'

Tags:

python

django

I had a custom user model in my project. I wanted to delete it and return default user model by deleting all tables in my database and deleting migrations. After this, I tried to run python manage.py makemigrations command but it writes:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
    django.setup()
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/contrib/contenttypes/apps.py", line 9, in <module>
    from .management import (
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/contrib/contenttypes/management/__init__.py", line 2, in <module>
    from django.db import DEFAULT_DB_ALIAS, migrations, router, transaction
  File "/home/irakliy01/Projects/Project/PythonVEnv/lib/python3.6/site-packages/django/db/migrations/__init__.py", line 1, in <module>
    from .migration import Migration, swappable_dependency  # NOQA
ModuleNotFoundError: No module named 'django.db.migrations.migration'

I have no idea what I did wrong.

like image 742
irakliy01 Avatar asked Feb 15 '18 16:02

irakliy01


2 Answers

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.

like image 120
Joel G Mathew Avatar answered Oct 19 '22 00:10

Joel G Mathew


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
like image 24
s4n7h0 Avatar answered Oct 18 '22 23:10

s4n7h0