15

Trying to follow the tutorial at Django project.

The problem I've come across is that when performing the command: python manage.py sql polls I'm given the error:

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

So far I can't seem to find any guide on the internet, or this website for a solution to the program.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
sneexz
  • 265
  • 2
  • 4
  • 10
  • 1
    Are you sure you are using django 1.6? What is the value of `INSTALLED_APPS` settings? Thanks. – alecxe Jun 13 '14 at 23:24
  • Im using django 1.8 right now, is 1.6 that needed? INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls' ) – sneexz Jun 13 '14 at 23:53
  • I got this error running the [PyCharm Django tutorial](https://www.jetbrains.com/pycharm/quickstart/django_guide.html) with Django 1.7.2, where the tutorial currently assumes Django 1.6.5. – Bob Stein Jan 06 '15 at 17:53

5 Answers5

31

You can either run python manage.py makemigration followed by python manage.py migrate or just delete migrations folder

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
tingyiy
  • 668
  • 7
  • 5
18

The problem is that you are using Django 1.8 while going through 1.6 tutorial. Pay attention to the first words at the beginning of the 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.

In your case, either downgrade to 1.6, or use the tutorial for the development (currently 1.8) version.

Anton K
  • 4,658
  • 2
  • 47
  • 60
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
3

Simply delete folder app-name/migrations.

In Django 1.7 and Python 3.4 the solution I found is to delete this folder and everything works now.

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
Evgeny Palguev
  • 599
  • 3
  • 18
  • 3
    This is kludgy at best. Migrations are an integral part of Django, and you should learn to work with them, not just delete stuff and hope for the best. – eykanal Mar 31 '15 at 12:59
  • Although eykanal is right, I had similar problem and this is simply the fastest answer. Sometimes hacking works and makes your life easier. *Sometimes.* – Olivier Pons Jul 27 '15 at 06:51
0

With django 1.7, instead of deleting app-name/migrations folder, In your MIGRATION_MODULES entry of your site, you can rename the application dictionary value with an non-existing module name by adding some dummy string:

MIGRATION_MODULES['my_app'] += '_xx'

And then manage.py sqlclear my_app works fine.

Alcolo47
  • 91
  • 1
  • 4
0

In Django 1.8, you should run another command--makemigrations [your app name]:

$ python manage.py makemigrations polls

You should see something similar to the following:

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