16

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?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Pablo
  • 163
  • 1
  • 1
  • 4
  • 1
    Why are you trying to import `migrations` from `django.db`? Where is this code located and how imported `migrations` is used in the code? – alecxe Sep 03 '14 at 19:01
  • 1
    What are you trying to achieve? – Joren Sep 03 '14 at 19:01
  • Actually I'm not trying to import migrations anywhere. That code is on the file to be migrated: It's code from the rest_framework.authtoken app, and as I explained above, is part of the error message that I'm getting. – Pablo Sep 04 '14 at 15:42

3 Answers3

21

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+.

sgarza62
  • 5,998
  • 8
  • 49
  • 69
  • While this is true, importing migrations should never be done. migrations is a tool to execute (via `python manage.py makemigrations` and `python manage.py migrate). It is not a package to import. – aliteralmind Sep 03 '14 at 20:04
  • @aliteralmind I completely agree. I didn't advocate for importing migrations :-) That being said, importing `migrations` wouldn't throw an error in Django 1.7. – sgarza62 Sep 03 '14 at 20:05
  • 1
    I understand that. The import it's not beeing made by me, it's included on the file that I'm trying to migrate. It's rest_framework.authtoken code. – Pablo Sep 04 '14 at 15:46
  • 1
    @Pablo Thank you for posting the additional information. Please check my edit for the solution. – sgarza62 Sep 04 '14 at 16:03
  • 4
    Upgrading to south 1.0 did solve my problem. Thanks @sgarza62 ! – Pablo Sep 04 '14 at 17:05
1

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.

MagicLAMP
  • 1,032
  • 11
  • 26
0

First of all, you never import migrations. It is not a module to import, it is a command tool to execute.

Second, migrations were introduced to Django in 1.7 version and you say you are using 1.5 so you won't be able to use it.

Before Django 1.7, people used to work with South because South gives you the ability to make migrations in databases. With Django 1.7 you don't need South anymore because migrations are already included in Django. In other words, South was included in Django in version 1.7.

Take a look at this link: https://docs.djangoproject.com/en/1.7/topics/migrations/

They explain that they included migrations into Django.

Actually, the last version of South is version 1.0 and they announced they won't be releasing more versions because they are working on Django 1.7 version where South was included. They will support current version but they won't add more features.

Take a look at this link: http://south.readthedocs.org/en/latest/releasenotes/1.0.html

They explain that 1.0 is the last major release of South because they are working on Django 1.7 migrations.

Carlos Calla
  • 6,556
  • 2
  • 16
  • 23