Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Django - error: 'No module named migration'

Tags:

python

django

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"
like image 254
A. Nurb Avatar asked Apr 20 '17 19:04

A. Nurb


2 Answers

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
like image 151
Tarun Sharma Avatar answered Sep 22 '22 17:09

Tarun Sharma


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.

like image 23
YPCrumble Avatar answered Sep 22 '22 17:09

YPCrumble