[Fixed]-Updating Django – error: 'No module named migration'

20👍

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.

30👍

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

5👍

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.

👤raj

3👍

Just reinstall the django version or upgrade the version. This solves my problem.

pip install --upgrade django==1.11.18

Then makemigrations

2👍

You must have deleted the migrations file

In that case try force reinstalling Django:

pip install --upgrade --force-reinstall  Django
👤PSN

1👍

Django models has a manage attribute.It can manage database table create or not create.manage is false not create database table, manage is true create tabe.

Class User(models.Model):
    username = models.CharField(max_length=255)

    Class Meta:
        manage = False
        manage = True
  • Drop database and create new database.
  • Update settings file (database connection).
  • Delete exist migrations files.
  • Create new migrations.
  • Run new migrations.

0👍

Try to place your virtualenv repository outside of your project. Or run the script in a path with it does not include your virtualenv repository.

Or you can exclude virtualenv repository from your find path. Check How to exclude a directory in find . command

Leave a comment