South: Unknown command 'migrate' - python

I'm getting a merciless
$ python manage.py migrate
Unknown command: 'migrate'
Type 'manage.py help' for usage.
I pulled the code from github onto a fresh computer. This code is tested and is working on other computers. The entire code runs fine except for the fact I can't run migrations!
Installed my virtual environment and ran pip install -r requirements.txt. It installs everything, including South. I can check by running
$ python manage.py shell
>>> import south
>>> south.__version__
'0.7.3'
However, when I run the manage.py help, the migrate and schemamigration commands don't appear listed.
I double checked that my settings.py file has 'south' listed under INSTALLED_APPS (I didn't change this file after pulling).
I tried pip uninstall south and then running pip install -r requirements.txt again, but I still get the same error.
Would really appreciate any help!

This is caused largely by following the 1.7 (DEV version) tutorial when we all get the last stable version (1.6) installed by pip.
Either follow the 1.6 tutorial or follow the instructions to install 1.7 dev version of Django.

Successful import of package is not enough for Django management commands. Python can import a package easy from a zipped egg but Django needs a normal uncompressed file.
Advices that simplify your problem initially:
Management commands must exist as files in a normal directory path..to..south/management/commands (not zipped).
Try to find and remove old installations of south manually.
A frequent problem was that one version of some package has been installed by easy_install (zipped) or manually by "python setup.py install" but pip didn't uninstall it and installed it for the second time.
Use only absolute directories in python path. Do not change the python path between installer and running Django either in environment or by customized manage or settings.py if possible. Some manage.py or settings.py use different python path than the one used by package intallers, e.g. added "." or ".." before other directories. You should not have other south directory in . or .. in your project.
The advice 1 is an absolute requirement of Django. The other two are heplful even if I use multiple versions somehow for testing my applications with multiple versions of Python, Django etc.
Example of investigation of the main requirement:
$ python manage.py shell
>>> import os
>>> import south.management.commands.migrate
>>> assert os.path.isfile(south.management.commands.migrate.__file__)

I solved this problem by going here http://south.readthedocs.org/en/latest/installation.html and using easy_install south. I then added 'south', to my INSTALLED_APPS and it worked.

I got the same error, but for a different reason. I did:
$ python manage.py migrate my_app --settings=settings_dev.py
But with the settings parameter, you should pass the name of the module not the name of the file. So it should have been
$ python manage.py migrate my_app --settings=settings_dev
You get a decent error message when you run the validate command like that, but when you run a south command, it'll say the command is unknown :/

In my case. south was already installed but later on requirements was the cause for other libraries:
pip install -r requirements.txt
I don't know why manage.py didn't complain about them.

I had this but it turned out to be an error in my settings.py which got shown up when I tried runserver instead. Fixed the error, and the command came back. Basically none of the management commands for any of the apps were there, so my INSTALLED_APPS must have been overwritten or never written in the first place. In my case, the import of the settings file was failing silently.

Related

How can I configure Django setup to not need sudo?

I have pip, virtualenv, and django installed globally. Using py3, default is set using alias line in ~./bash_profile - so py2 packaged with Mac still there.
In new virtualenv, activated, but when I try to do anything with django get following error:
$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
If I run with sudo (i.e. sudo python manage.py migrate) command works.
I know problem is likely how I installed pip, but anyway to fix this without re-installing everything?
Instead of python manage.py migrate, simply tell it python. It will start an interactive python interpreter. Tell it the following:
import sys
sys.executable
sys.path
sys.executable is the full pathname of the Python executable. It should be something inside your virtualenv. sys.path is the list of directories in which Python searches for modules whenever you try to import something. This should include your virtualenv.
Now exit Python and tell it sudo python. Enter the same directives. What are the differences?
This should give you a hint on what you've done wrong and you should be able to debug it further.
You might also find my article, virtualenv demystified, useful.
This can happen for several different reasons (from most basic to more complicated):
Django not installed, either globally, in your virtualenv, or both. Check using pip list. Most of the time pip install django will fix. Do not sudo this, or you will have to sudo everything. Also: double check django version matches python version; pip install --upgrade django to get latest version.
Virtualenv not activated - use source your_path/venv/bin/activate
Mac users - running python3 on virtualenv, but python2.7 default on comp. Fix by deactivating first virtualenv, manually deleting bin||venv, start new virtualenv set to use python2.7. Use virtualenv -p /usr/bin/python2.7 env.
Similar - server running different versions. Sometimes you can fix with alias (ala alias python=python2.7), but make sure to only use on instance being used for project, not on local comp. Local comp wont work, because sudo being run for default python version regardless.
In manage.py defaulted path not correct. This depends on your setup and where python dependencies stored. If this is your problem, replace shebang with #!/usr/bin/env python. Be careful re: python versions here, so if issue with OS default different from using, just add number to end of python (ex: python3).
Follow #antonis answer, figure out where in $PYTHONPATH not matching up with sudo PATH. Pipe/update profile to fix.

Manage.py utitliy not working properly within Pycharm

I happened to change the name of a django's app (just the name of the directory) so everytime I wanted to make the migrations of the models within that app, I couldn't.
After updating every occurence of the string within the project, I run makemigrations succesfully within the terminal. But I haven't been successful doing so within Pycharm, apparently it is stuck on the lastest -failed- command, whenever I type makemigrations app_name (or any othe command like shell) it throws the same message I was seeing prior fixing the error (updating the string):
ImportError: No module named 'app_name'
Any help?
Is maybe not the best solution to your problem but I had something similar in the past with PyCharm and what I did was to recreate the virtualenv within PyCharm and reinstall all the modules. Make sure that you export your installed modules using the following command:
pip freeze > requirements.txt
and then install in the new virtualenv using:
pip install -r requirements.txt

Unable to run migrate command on command line and PIP freezes

I am using python 3 and never installed python 2 on this PC. Trying to install and use Django. I was trying to use pip to download it but when I enter pip install django==1.8 on my command line, nothing happens. No error messages, no further information. Command line just seems to freeze.
I checked if my pip was installed by running import pip on my python shell and able to do it. I ended up downloading django and installing it via a .gz file. For checking, I tried using the python shell and able to import django.
I have now created a virtual environment and activated it and my command line looks as follows now:
(myenv) c:/....... thus am in my virtual environment.
I started a new project in using django-admin startproject mysite .
The mysite folder is created alone with a manage.py file.
Next up when I try to run the command python manage.py migrate ,
I get the following error:
from django.core.management import execute_from_command_line
ImportError: No module name 'django'
My manage.py file header is correct with the following line - #!/usr/bin/env python
Am I supposed to install django again in each individual virtual environment I create? If yes how do I do it since pip is jamming up.
Am I supposed to mess with environment variable PATH for this? Can someone help please. Went through similar cases here and none is helping.
Am I supposed to mess with environment variable PATH for this?
No.
Am I supposed to install django again in each individual virtual environment I create?
Yes.
If yes how do I do it since pip is jamming up?
Even if you develop in Windows, it is really good practice to keep your environment in a linux virtual machine, and use bash scripts to prepare it, so if something goes unexpected, you can easily destroy it and spin it up again. One way of doing so is installing VirtualBox + Vagrant.
One example of bash script is here: https://github.com/torchbox/vagrant-django-template
See the Vagrantfile, and etc/install.sh. Hope that helps.

How to get Django classifieds running on my local server

I am starting on a project for classified ad listing site and found a template to get me started.
The installation instruction on git are not clear to me.
I created virtual env and installed dependencies using pip but I can't finish the installation process: manage.py runserver could not be executed and showed "could not find module sorl.thumbnail".
I think there is some error due to folder structure but cannot figure out what. Any ideas?
This is my folder structure.
It seems that the dependency sorl.thumbnail is not (successfully) installed.
Try running pip install sorl-thumbnail==11.05.2. That should install the module (in the version required by django-classifieds according to the requirements.txt). Check the output for any errors.
Also, make sure that you are using the right environment.
My only guess is that you either forgot to install sorl.thumbnail or that it is in a separate environment than django-classifieds. To add it manually, download the zip from the specified URL, extract the zip, and, in a command prompt/terminal in the directory you extracted the zip into, and run python setup.py build and python setup.py install.

Django-admin.py not being recognized suddenly

I tried starting a new Django project yesterday but when I did "django-admin.py startproject projectname" I got an error stating: "django-admin.py is not recognized as an internal or external command." The strange thing is, when I first installed Django, I made a few projects and everything worked fine. But now after going back a few months later it has suddenly stopped working.
I've tried looking around for an answer and all I could find is that this typically has to do with the system path settings, however, I know that I have the proper paths set up so I don't understand what's happening. Does anybody have any idea what's going on?
First check the django was installed properly.
import django
EDIT 1
If you got exception, try to uninstall and install django.
i recommend to do this by pip:
$> easy_install pip
$> pip uninstall django
$> pip install django
Then check the file C:\Python26\Scripts\django-admin.py exists.
you may replace c:\python26 by your local python installation path.
if you not found the file, so uninstall and install django, see EDIT 1 above.
then add C:\Python26 and C:\Python26\Scripts to your path. see here
From python documents:
to the current setting for the PATH environment variable, which you will find in the properties window of “My Computer” under the “Advanced” tab. Note that if you have sufficient privilege you might get a choice of installing the settings either for the Current User or for System. The latter is preferred if you want everybody to be able to run Python on the machine.
i am totally new to coding, so pardon my amateur answers.
I had similar problem - i realized that while my Django was installed on C Drive, my files were saved on D drive and i was trying to run django-admin from D drive in the command prompt which was giving the above error. what worked for me was the following
Located the Django-admin.exe and django-admin.py file which was in below path
C:\Users[Username]\AppData\Local\Programs\Python\Python38-32\Scripts>
copied both these files into the D drive folder where i was trying to create new projects
then on the terminal command prompt (which was set to D Drive projects) ran django-admin startproject [filename] and it created a new file [filename]in that folder and this error was resolved
You can try with following code
py -m django startproject add_your_project_name_here
As per this link you may try,
python -m django <command> [options].
Where python is the version of the python you are using.
Usage python -m django startproject <projectname>.

Categories