How to Solve Django Error Message : Unknown command : ‘makemigrations’

Posted on

This article is depicting on the situation or condition happened as stated in the title of this article. When an application is being developed using Django framework which is based on Python programming language, the error message occurred. It is shown as follows :

user@hostname:~/python/appproject$ python manage.py makemigrations applist
Unknown command: 'makemigrations'
Type 'manage.py help' for usage.
user@hostname:~/python/appproject$ python manage.py migrate
Unknown command: 'migrate'
Type 'manage.py help' for usage.
user@hostname:~/python/appproject$ python manage.py makemigrations
Unknown command: 'makemigrations'
Type 'manage.py help' for usage.
user@hostname:~/python/appproject$

Turns out that the version of the django is not update. So, in order to solve the above problem, just update the django version. In this context of the article, it is done by executing the following steps :

  1. Since it is the update of django version, it must be executed in ‘root’ user account. So, switch to root by executing the following command :
user@hostname:~/python/appproject$ sudo su -
[sudo] password for user:
user@hostname:~#

2. Just execute the following command to update the django version installed :

root@hostname:~# pip install --upgrade django
Collecting django
  Downloading https://files.pythonhosted.org/packages/25/4d/c8228419346a0e84aec202a43e181afc6572b861d38f8a0306dbce6abef0/Django-1.11.13-py2.py3-none-any.whl (6.9MB)
    100% |████████████████████████████████| 7.0MB 459kB/s 
Requirement not upgraded as not directly required: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2018.3)
Installing collected packages: django
  Found existing installation: Django 1.5.5
    Uninstalling Django-1.5.5:
      Successfully uninstalled Django-1.5.5
Successfully installed django-1.11.13
root@hostname:~#

3. Try to check the django version. It can be done by executing the following command :

user@hostname:~/python/appproject$ django-admin.py --version
1.11.13
user@hostname:~/python/appproject$

After checking the django version, the next step is to re-execute the command above which is the python manage.py makemigrations.

user@hostname:~/python/appproject$ python manage.py makemigrations applist
Migrations for 'applist':
  applist/migrations/0001_initial.py
    - Create model File
user@hostname:~/python/appproject$ 

Just check the file in the applist application which is located inside the folder appproject whether the migration script has already been created or not. Below is the folder’s structure of the project directory :

user@hostname:~/python/appproject$ tree -L 3
.
├── applist
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0001_initial.pyc
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   └── views.py
├── appproject
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── db.sqlite3
├── manage.py
└── templates
    └── applist

5 directories, 22 files
user@hostname:~/python/appproject$

Inside the folder named ‘migrations’, there is a file created named ‘0001_initial.py’. The command has been successfully carried out.

Leave a Reply