Django: Error: Unknown command: 'makemigrations'

可紊 提交于 2019-12-31 11:43:32

问题


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


回答1:


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




回答2:


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



回答3:


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.




回答4:


In django makemigration added after 1.7 so if you are using older version of Django then you have to change settings.py and add your application in installed app like

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

and then you can run command

python manage.py syncdb




回答5:


You need to load the virtual environment before doing it.

Use below code for Linux/OSX:

source venv/bin/active

And the following code for Windows

source venv/Scripts/activate



回答6:


I did following (for python version 3.6.4) to get this issue resolved:

  1. install virtualenv
  2. Activate virtualenv

Cheers




回答7:


First time I add following piece of code into project_name\settings.py file.

                  `INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        #Django REST Framework
        'rest_framework',
        #Games application
        'games.apps.GamesConfig',
                  ]`

After save it, when run following code I got error.

                 `python manage.py makemigrations games`

Then I check the settings.py file I realize that there are two INSTALLED_APPS and second one has not followings. When I added these the code worked.

       `#Django REST Framework
       'rest_framework',
        #Games application
       'games.apps.GamesConfig',`


来源:https://stackoverflow.com/questions/20250123/django-error-unknown-command-makemigrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!