简体   繁体   中英

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?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM