Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Error: Unknown command: 'makemigrations'

I am trying to follow the Django tutorial and I faced the following error when I enter python manage.py makemigrations polls

Unknown command: 'makemigrations'

Here's the link to the tutorial and I accomplished all the previous steps successfully and I am not sure what's going wrong now or how to fix it. P.S.: I have already included "polls" in the INSTALLED_APPS!

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
    'South',
)

Answer: I had to modify INSTALLED_APPS to :

INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'polls',
    )

and also used this command: python manage.py syncdb

like image 990
Mona Jalal Avatar asked Nov 27 '13 18:11

Mona Jalal


People also ask

What does Makemigrations command do?

makemigrations basically generates the SQL commands for preinstalled apps (which can be viewed in installed apps in settings.py) and your newly created apps' model which you add in installed apps. It does not execute those commands in your database file.

What is the difference between migrate and Makemigrations?

migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.

What does migrate command do in Django?

migrate executes those SQL commands in the database file. So after executing migrate all the tables of your installed apps are created in your database file. You can confirm this by installing SQLite browser and opening db.


3 Answers

Migrations were first added in version 1.7, officially released on September 2, 2014. You need to make sure your tutorial matches the version of Django you're working with. For instance, this version of the tutorial covers 1.9:

https://docs.djangoproject.com/en/1.9/intro/tutorial01/

Or, if you're using an older version of Django, you can change the "1.9" in that URL to whatever version you're on (back to 1.3). Or use the dropdown on the docs page to pick the version and search for "tutorial".

like image 72
Peter DeGlopper Avatar answered Oct 19 '22 12:10

Peter DeGlopper


Find out what version of django you're running (thanks @BradyEmerson):

python -c "import django; print(django.get_version())"

If older than 1.8:

pip install --upgrade django
like image 3
Bob Stein Avatar answered Oct 19 '22 14:10

Bob Stein


I was using version 1.9 and still getting this error. I had unapplied migrations and that was the root cause in my case. I ran 'python manage.py migrate' to apply them and it worked for me.

like image 2
Kunal Priyadarshi Avatar answered Oct 19 '22 12:10

Kunal Priyadarshi