Django: Error: Unknown command: 'makemigrations' - python

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

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

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

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.

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

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

I did following (for python version 3.6.4) to get this issue resolved:
install virtualenv
Activate virtualenv
Cheers

This worked for me: using ubuntu 20.04, Django 3.2
First after creating the model and addind to the setting, I did:
python manage.py makemigrations
I obtained the migration number here.
After that I did:
python manage.py sqlmigrate [NAME_OF_MODEL] [NUMBER_OF_THE_MIGRATION]
Finally:
python manage.py migrate

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',`

Related

Django don't makemigrations my apps after I install app in INSTALLED_APPS

Those are my installed applications:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'stu',
'stu2',
]
When using magane.py makemigrations I get those errors (I'm using Ubuntu):
ashish#ashish-MS-1050:~/Desktop/aculance/test1$ python3 manage.py makemigrations stu
No installed app with label 'stu'.
ashish#ashish-MS-1050:~/Desktop/aculance/test1$ python3 manage.py makemigrations stu2
No installed app with label 'stu2'.
I tried many times to apply migrations but it can't recognise my app
and gives me this error:
No installed app with label 'stu'.

Heroku app: ModuleNotFoundError: No module named 'pwa'

I am trying to deploy my app to heroku and I keep getting this error even though when I run locally it works perfectly fine. I have added django-pwa==1.0.10 to my requirments.txt file also so that heroku installs the package. Here are my installed apps in settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pwa',
# 'embed_video',
'whitenoise.runserver_nostatic',
'courses.apps.CoursesConfig',
'accounts.apps.AccountsConfig',
'announcements.apps.AnnouncementsConfig',
'students.apps.StudentsConfig',
'home.apps.HomeConfig',
'event_calendar.apps.EventCalendarConfig',
]
Here is my directory
Not really sure what to do as I am not very experienced with heroku.
By default Heroku will try to install every app from your requirements.txt, so before going any further make sure of the following:
You have run pip freeze > requirements.txtto reflect the change
Your path for the Procfile is correct
If it does not work after the troubleshooting, add your log from heroku to your first question, your procfile and requirements.txt.
Learning about procfile

Error generation due to settings.py in django

-Created a project in django with 'CustomUser' model derived from 'AbstractUser' in an app 'users'
-Below is the settings file snippet.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'crispy_forms',
'users',
I get following error while running python manage.py makemigrations command with unsuccessful migration.
ValueError: The field authtoken.Token.user was declared with a lazy reference to 'users.user', but app 'users' doesn't provide model 'user'.
After much trial and error, I have removed 'rest_framework.authtoken' from the Installed app and the migration error disappeared and my site become functional. Problem is I want to user rest_framework and token based authorisation but if I keep 'rest_framework.authtoken' in settings, migration is not taking place.
Please help

problems setting up django-toolbar: the bar is not shown

I am trying to set up django-toolbar in my production site, so just certain IPs can use it. I have followed the official documentation (install and quick setup), but I can't see the toolbar.
The app is installed:
$ yolk -l | grep toolbar
django-debug-toolbar - 0.11.0 - active
I have added the required settings:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.sitemaps',
'modeltranslation',
'djangocms_text_ckeditor',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'debug_toolbar',
# more stuff...
)
INTERNAL_IPS = ('---.---.---.---',) # my current ip, taken from the server logs so I'm sure it's correct
STATIC_URL = '/static/'
DEBUG = True
There's no error message. I have also run collectstatic just in case. No success.
Any suggestion? Thanks :-)
EDIT: it seems that the order within INSTALLED_APPS matters. Moving 'debug_toolbar' right after all 'django.contrib.*' and before 'modeltranslation' and the others solved the issue.
Have you set the INTERNAL_IPS to what is in request.META['REMOTE_ADDR'] (second answer here)?
I had a similar problem, the toolbar wasn't displaying and I couldn't figure out why. But when I printed request.META['REMOTE_ADDR'] my IP wasn't what I thought it was! (because I was using port forwarding and virtual box).
I found out the reason. Within INSTALLED_APPS, 'debug_toolbar' must appear as soon as possible. I had placed some other applications before ('modeltranslation', 'cms', etc.). Placing it just after all 'django.contrib.*' and before the others works fine.

No module named pages.urls

I'm trying to install Django Gerbi-CMS and getting no luck. I've got through the installation a couple of times and not getting anywhere. When I run the server I get the error:
No module named pages.urls
When I install it tells me that it's installed correctly. However I look in the python2.7/site-packages and pages is not in there.
I installed on an existing site a while ago and I can't see what different other than pages and the other depencencies not showing in the above directory.
The last command I ran to install the package was:
$ sudo pip install django-page-cms
which like I said installed but nothing showing up in my site-packages.
Link to site - http://packages.python.org/django-page-cms/installation.html
SETTINGS:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
#'authority',
'pages',
'south',
'blog',
)
URLs:
if settings.DEBUG:
urlpatterns += patterns('',
# Trick for Django to support static files (security hole: only for Dev environement! remove this on Prod!!!)
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
url(r'^admin_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.ADMIN_MEDIA_ROOT}),
)
urlpatterns += patterns('',
(r'^', include('pages.urls')),
)
If you need any other info please let me know.
Thanks!
After going through the installtion process several times I worked out that because I was using 'sudo' it was installing on the server and not inside the virtualenv!
So when you install the app you need to Install it without sudo, otherwise it will install outside of the virtualenv!
Did you included the application in your settings.py file in the section called
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'mptt',
'tagging',
'pages', # You have to include it here
)

Categories

Resources