Python Django:错误:未知命令:'makemigrations'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20250123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django: Error: Unknown command: 'makemigrations'
提问by Mona Jalal
I am trying to follow the Djangotutorial and I faced the following error when I enter python manage.py makemigrations polls
我正在尝试按照Django教程进行操作,但在输入时遇到以下错误python manage.py makemigrations polls
Unknown command: 'makemigrations'
Here's the linkto 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!
这是教程的链接,我成功完成了前面的所有步骤,但我不确定现在出了什么问题或如何修复它。PS:我已经在 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 修改为:
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
并且还使用了这个命令: python manage.py syncdb
采纳答案by Peter DeGlopper
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:
迁移最初是在 2014 年 9 月 2 日正式发布的 1.7 版中添加的。您需要确保您的教程与您正在使用的 Django 版本相匹配。例如,此版本的教程涵盖 1.9:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/
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".
或者,如果您使用的是旧版本的 Django,您可以将该 URL 中的“1.9”更改为您使用的任何版本(回到 1.3)。或者使用文档页面上的下拉菜单选择版本并搜索“教程”。
回答by Bob Stein
Find out what version of django you're running (thanks @BradyEmerson):
找出您正在运行的 django 版本(感谢@BradyEmerson):
python -c "import django; print(django.get_version())"
If older than 1.8:
如果早于 1.8:
pip install --upgrade django
回答by Kunal Priyadarshi
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.
我使用的是 1.9 版,但仍然收到此错误。我有未应用的迁移,这就是我的案例的根本原因。我跑 ' python manage.py migrate' 来应用它们,它对我有用。
回答by bhatt ravii
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
在 1.7 之后添加的 django makemigration 所以如果您使用的是旧版本的 Django 那么您必须更改 settings.py 并将您的应用程序添加到已安装的应用程序中
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
python manage.py syncdb
回答by user3704354
You need to load the virtual environment before doing it.
您需要在执行此操作之前加载虚拟环境。
Use below code for Linux/OSX:
对 Linux/OSX 使用以下代码:
source venv/bin/active
And the following code for Windows
以及以下适用于 Windows 的代码
source venv/Scripts/activate
回答by Akshay Lokur
I did following (for python version 3.6.4) to get this issue resolved:
我做了以下(对于python版本3.6.4)来解决这个问题:
- install virtualenv
- Activate virtualenv
Cheers
干杯
回答by Sibel Kahraman
First time I add following piece of code into project_name\settings.py file.
我第一次将以下代码添加到 project_name\settings.py 文件中。
`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.
然后我检查 settings.py 文件我意识到有两个 INSTALLED_APPS 而第二个没有以下内容。当我添加这些代码时。
`#Django REST Framework
'rest_framework',
#Games application
'games.apps.GamesConfig',`

