Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
Updating Django - error: 'No module named migration'

I'm upgrading my Django App from Django 1.5.5 tot 1.9, Django-cms from 2.4.3 to 3.3 (and all corresponding packages).

After I've plowed through all the errors of depreciated functions I now stumble on an error that I cannot understand: 'No module named migration'

I get this error when running (in a virtualenv): - python manage.py runserver and also when I run - python manage.py migrate

Traceback (most recent call last):
  File "manage.py", line 20, in <module>
    execute_from_command_line(sys.argv)
  File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 195, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 39, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/var/www/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 16, in <module>
    from django.db.migrations.autodetector import MigrationAutodetector
  File "/var/www/env/local/lib/python2.7/site-packages/django/db/migrations/__init__.py", line 1, in <module>
    from .migration import Migration, swappable_dependency  # NOQA
ImportError: No module named migration

manage.py

#!/usr/bin/env python2
import os
import sys

if __name__ == "__main__":

    settings_module_path = 'ais.settings.production'
    ########## Attempt to override settings using local settings
    try:
        from ais.settings.local_settings import *
        # For developmentent, file will probably hold the following:
        settings_module_path = 'ais.settings.development'
        print "!!!manage.py settings overwritten!!!"
    except ImportError:
        pass
    os.environ['DJANGO_SETTINGS_MODULE'] = settings_module_path

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

migrate.sh

#!/bin/sh
echo "Starting ..."

echo ">> Deleting old migrations"
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc"  -delete


# Optional
echo ">> Deleting sqlite  (if exists) database"
find . -name "db.sqlite3" -delete

echo ">> Running manage.py makemigrations"
python manage.py makemigrations

echo ">> Running manage.py migrate"
python manage.py migrate

echo ">> Done"
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

If your error still like :

 from .migration import Migration, swappable_dependency  # NOQA
ImportError: No module named 'django.db.migrations.migration'

You need to reinstall dajngo

Check You Django version and then Force Reinstall it

python -m django --version

pip install --upgrade --force-reinstall package

  pip install --upgrade --force-reinstall  Django==2.0.5
about 4 years ago · Santiago Trujillo Report

0

Your script appears to be the problem. It is trying to delete your migrations, but it's actually also deleting the contents of Django's /django/db/migrations/ file as well. Note that it explicitly doesn't delete the __init__.py file but it does delete the others.

One option is just to remove these lines:

echo ">> Deleting old migrations" 
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete 
find . -path "*/migrations/*.pyc"  -delete

You shouldn't be deleting old migrations anyway once you're running Django on production because you might want to add custom code to a migration. This looks like a convenience script for development.

about 4 years ago · Santiago Trujillo Report

0

As @YPCrumble pointed out, your ">> Deleting old migrations" script deleted /django/db/migrations/ file as well. To restore it back, you need to uninstall Django and reinstall it.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!