Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from django.db import models, migrations ImportError: cannot import name migrations

So I've started to experience some issues with south on my Django web server. Migrate command is failing with this output everytime:

from django.db import models, migrations

ImportError: cannot import name migrations 

(Above this the error displays the rout to the file that failed to be migrated)

My Django version is 1.5.1, while my south version is 0.8.4

The thing that troubles me the most is that the module django.db.migrations is nowhere to be found.

Any ideas?

like image 292
Pablo Avatar asked Sep 03 '14 18:09

Pablo


2 Answers

Migrations were introduced in Django 1.7; you are using 1.5.

Here is a link to the docs explaining this. If you're using an older version of Django, South is the most popular option for data migrations.


EDIT

So the Django Rest Framework is causing the error. From their documentation:

The rest_framework.authtoken app includes both Django native migrations (for Django versions >1.7) and South migrations (for Django versions <1.7) that will create the authtoken table.

Note: From REST Framework v2.4.0 using South with Django <1.7 requires upgrading South v1.0+

You must upgrade South beyond your version of 0.8.4 to 1.0+.

like image 151
sgarza62 Avatar answered Nov 14 '22 06:11

sgarza62


I think the OP did not import migrations into a script he was writing, one of the automatic scripts created by schemamigration may have been causing the problem.

This error suddenly started appearing for me where migrations had worked before, and I found that it was not to do with the versions of Django==1.6.1 and South==0.8.4, but with my shell becoming confused as to which virtualenv I was using. I had quit one virtual environment with deactivate and started another with "workon" and run a schemamigration in order to change the name of a field. When I ran ./manage migrate, I got the error. I quit the shell and started the virtualenvironment again, and everything was fine.

like image 1
MagicLAMP Avatar answered Nov 14 '22 07:11

MagicLAMP