What causes "Unknown command: 'mkmigrations'" in Django? - django

When attempting to view my Django app while being served locally I am encountering this error:
A server error occurred. Please contact the administrator.
It remains that way even when debug is false. The console shows:
django.core.exceptions.ImproperlyConfigured: Module "django.contrib.auth.
are" does not define a "SessionAuthenticationMiddleware" attribute/class
and searching around I came across the suggestion to comment out
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
This does indeed fix the problem, in that the app does display, however when I go to the admin panel I get the message:
Site administration
You don't have permission to edit anything.
I figured I would just try and roll back to the last commit before I pushed the app to heroku and ran:
git reset --hard 'appropriate commit'
This did not seem to do anything at all. I still have the same situation as previously. Furthermore running:
python manage.py makemigrations
or
python manage.py migrate
results in
Unknown command: 'makemigrations'
Type 'manage.py help' for usage.
and
Unknown command: 'migrate'
Type 'manage.py help' for usage.
Previously both of these commands worked just fine.
If it helps, I was trying to install addthis to the app when things started breaking. Also after the git reset when I type git status I get:
Untracked files:
blog/migrations/0005_join_ip_address.py
blog/migrations/0006_auto_20150318_1716.py
blog/migrations/0007_remove_join_ip_address.py
no changes added to commit (use "git add" and/or "git commit -a")
Other details:
Django 1.6.5
Python 3.4.1 |Anaconda 2.1.0
Using a Virtualenv
Any help would be massively appreciated.

As others have noticed, your Django version should be 1.7; this is caused by your installation of django-addthis.
The current version of django-addthis explicitly states Django<=1.6.5 as a dependency. For some reason, this prompts pip to downgrade your installation:
$ pip install django-addthis
Downloading/unpacking django-addthis
Downloading django-addthis-2.0.0.tar.gz
Running setup.py (path:...) egg_info for package django-addthis
Downloading/unpacking Django>=1.4,<=1.6.5 (from django-addthis)
Downloading Django-1.6.5-py2.py3-none-any.whl (6.7MB): 6.7MB downloaded
Installing collected packages: django-addthis, Django
Running setup.py install for django-addthis
Found existing installation: Django 1.7.5
Uninstalling Django:
Successfully uninstalled Django
Successfully installed django-addthis Django
The last four lines show what happened when I tried this on one of my own Django 1.7 projects. pip happily downgrades your Django app. And since virtualenv dependencies are usually not stored in Git, you won't see this when you do a git status.
The only solution is to uninstall django-addthis and reinstall the correct Django version:
$ pip uninstall django-addthis && pip install --upgrade -r requirements.txt

You are running a Django 1.7 project against an installed version of 1.6. Upgrade your Django installation.

Related

Can't find any modules in Django project

I've been following a Django tutorial and initially created virtualenv and a requirements file in it. Project was halfway and in working state. Today I activated virtualenv successfully and tried python manage.py runserver to get error
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I realized it's not finding Django and just to be sure checked my requirements.txt file (which confirmed right Django version). Tried to reinstall it from the file using pip3 install -r requirements.txt (tried using just pip too) to get another error --
ModuleNotFoundError: No module named 'pip'
It seems the environment is unable to find any of the modules. I tried to reinstall pip also just to be sure, but then it couldn't find apt-get command.
OS: Mac OSX El Capitan 10.11.6
Python: 3.6.2
Django: 1.10.3 (in requirements file)
Try running python -m ensurepip (or python3 -m ensurepip) to see if pip is already installed:
In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.

Heroku gettext installation

I want to install gettext in Heroku. I have added: https://github.com/lexifdev/heroku-buildpack-gettext.git into the buildpacks section of my app. However, when I run
heroku run python manage.py compilemessages -l en
I get the error message: CommandError: Can't find msgfmt. Make sure you have GNU gettext tools 0.15 or newer installed.
Had the same problem my friend. Here's how I fixed it:
From the heroku dashboard, add the following buildpack: https://github.com/grauwoelfchen/heroku-buildpack-gettext.git
On your next deployment to heroku (e.g. a git push), it and any other buildpacks you have will be built and installed and all should work.
Here is how I did it
type the following commands
heroku buildpacks: add https://github.com/grauwoelfchen/heroku-buildpack-gettext
git push heroku master
Now, the gettext will be added

Django Twilio module is not getting installed on Heroku

I tried below 2 methods to install django_twilio module on Heroku
1) Ran 'heroku run pip install django-twilio'
2) Added 'twilio==3.6.3' to requirements.txt and start the server on heroku.
When I run 'heroku run pip freeze' I can see the twilio entry. But when I go into python and run 'import django_twilio' I get a module not found error.
Please suggest how to fix this on heroku. Same steps worked fine on my local machine.
You didn't add the proper requirement, you only installed the twilio library. Your requirements.txt should include the following line:
django-twilio==0.4
Which will include all the other dependencies you'll need. The full pip freeze, after installing django-twilio looks like this:
Django==1.5.5
django-twilio==0.4
httplib2==0.8
six==1.4.1
twilio==3.6.3
unittest2==0.5.1
As a rule of thumb, always run pip freeze > requirements.txt before pushing an update to Heroku (assuming new dependencies were installed), to make sure you have a complete snapshot of your environment.

Manage.py : Unknown command: 'migrate'

I'm using django and I'm facing a little problem. I would like to use the 'migrate' command with manage.py But when I try I get this error message:
Unknown command: 'migrate'
Type 'manage.py help' for usage.
I have south installed (I installed it with pip), but I still can't use this command. I don't know what to do.
Thank you for your help!
You have to include south in INSTALLED_APPS in your settings.py.
This is likely caused by following the 1.7 (DEV version) tutorial when we all get the last stable version (1.6) installed by pip.
It would not appear migrate is even a part of 1.7 in general!
Maybe the following command solve your problem: python manage.py syncdb
So either follow 1.6 tutorial or follow the instructions to install the 1.7 dev version of Django.

Django : Cannot Import name xrange

I am new to python and django. I had django running properly in my machine, till I installed django-haystack. I directly downloaded django-haystack.zip from github and executed 'python setup.py install' in haystack dir. After this whenever I run 'django-admin.py runserver' I am getting the following error : ImportError: cannot import name xrange.
If I remove 'haystack' from INSTALLED_APPS the above command is working fine.
I also cannot run 'python manage.py build_solr_schema' because of the same error.
Let me know how I can resolve this issue.
Solved the issue. Deleted the haystack installation from /usr/local/.../dist-packages/ and used pip install django-haystack to install. That worked fine
This:
http://pypi.python.org/pypi/haystack/
is not the same as this:
http://pypi.python.org/pypi/django-haystack
but if you have them both in your requirements.txt file for some reason, like so:
haystack
django-haystack
and install them into the same virtualenv then you will have problems because they both want to unpack to a directory named 'haystack'. 99% of the time if you're doing django development you don't want that first one at all. So remove it from the requirements.txt file, remove all traces of anything to do with haystack from your virtualenv and then reinstall with:
pip install -r requirements.txt
and you should be good to go.
if you have installed haystack and django-haystack, uninstall both haystacks and install django-haystack
pip uninstall haystack
pip uninstall django-haystack
pip install django-haystack
if you have it installed and still this error appears
uninstall haystack and reinstall it
pip uninstall haystack
#here ask for y/n type y :)
pip install haystack
that works for me