2014-06-13 36 views
15

试图按照教程Django projectDjango CommandError:应用程序“民意调查”已迁移

我遇到的问题是,在执行命令时: python manage.py sql polls我给出的错误:

CommandError: App 'polls' has migrations. only the sqlmigrate and sqlflush commands can be used when an app has migrations

到目前为止,我似乎无法找到在互联网上的任何指导,或本网站提供该方案的解决方案。

+1

你确定你正在使用django 1.6? 'INSTALLED_APPS'设置的价值是什么?谢谢。 – alecxe

+0

我现在在用django 1.8,需要1.6吗? INSTALLED_APPS =( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', \t'民意调查' ) – sneexz

+0

我得到这个错误在Django 1.7上运行[PyCharm Django教程](https://www.jetbrains.com/pycharm/quickstart/django_guide.html)。 2,其中教程目前假设Django 1.6.5。 –

回答

18

问题在于您在使用1.6教程时使用Django 1.8。在tutorial的开始就要注意了第一句话:

This tutorial is written for Django 1.6 and Python 2.x. If the Django version doesn’t match, you can refer to the tutorial for your version of Django by using the version switcher at the bottom right corner of this page, or update Django to the newest version.

在你的情况下,可以降级到1.6,或者使用tutorial for the development (currently 1.8) version

31

您可以运行之后python manage.py migratepython manage.py makemigration或直接删除文件夹迁移

+5

删除migrations文件夹就像一个魅力! –

+0

什么是migrations文件夹?什么是**迁移**在这种情况下? –

+4

该命令是python manage.py makemigrations not makemigration –

3

简单地删除文件夹app-name/migrations

Django 1.7Python 3.4我找到的解决方案是删除此文件夹,现在一切正常。

+3

这是最好的。迁移是Django的一个组成部分,您应该学会与他们合作,而不仅仅是删除内容并希望获得最佳效果。 – eykanal

+0

虽然eykanal是正确的,但我有类似的问题,这只是最快的答案。有时候黑客行为会让你的生活更轻松。 *有时。* –

0

使用Django 1.7,而不是删除的应用程序名称/迁移的文件夹,在您的网站你MIGRATION_MODULES进入,您可以通过添加一些虚拟的字符串重命名一个不存在的模块名称应用字典值MIGRATION_MODULES ['my_app'] + ='_xx'

然后manage.py sqlclear my_app工作正常。

0

在Django的1.8,你应该运行另一个命令 - makemigrations [您的应用程序名称]:

$ python manage.py makemigrations polls 

你应该会看到类似下面的内容:

Migrations for 'polls': 
    0001_initial.py: 
    - Create model Question 
    - Create model Choice 
    - Add field question to choice