Django South Error: "there is no enabled application matching 'myapp'" - python

So, I finally gave in and grabbed South. The problem is, every time I try to follow the tutorial and run
"python manage.py schemamigration myapp --initial"
I get an error
"There is no enabled application matching 'myapp'"
--Things I have tried--
I have tripple checked my settings file, running Import South from the django shell returns no errors, and I have added manage.py containing folder to PYTHONPATH, as well as wsgi.py and settings.py.
I have run python manage.py and python C:\path\to\manage.py variants, even went into my python directory and verified that south was in the site-packages folder. syncdb runs fine, ending with "not synced (use migrations)". python manage.py migrate runs without returning errors but otherwise seems to have no effect. I have tried running the said command both before and after running syncdb, which has no effect on the outcome.
--Other potentially pertinent info--
Django 1.5.1, Python 2.7, no other external apps used, Windows 7 64 bit, python is added to the windows path, South installed via python setup.py install command. Installation completed successfully. I do not use a virtualenv, and would really prefer to avoid this as it would mean alot of refactoring of this current project's setup and wasted time. I plan to move to a virtualenv setup in the future, but not now.
What's going on? How do I fix this? Net searches revealed no good info at all, I am completely at a loss...

This error can be misleading: it is thrown not when South tries to import the app, but when it tries to get the app's models module.
perhaps it cannot import the application (because you didn't add its name to INSTALLED_APPS)
perhaps it cannot import the models module, because the file models.py does not exist, or because the directory models/ does not contain an __init__.py.
South doesn't import the models module itself. Instead, it leaves that job to django.db.models.get_app('app_of_interest'), which according to its docstring "Returns the module containing the models for the given app_label." The error message raised by get_app is, in fact, different depending on whether it failed to import the app or the model, but both exceptions are ImproperlyConfigured, and the schemamigrations script doesn't look any deeper than that.
Because South says it is accepting security updates only (it entered end-of-life with Django 1.7's migration feature), I'm not submitting a fix to its codebase, but instead documenting the problem here.

migrations exist on a per-app basis. each app may or may not have its own migrations, but you need to create them for each app where you want to use them. (often all apps)
./manage.py migrate is a shortcut that runs migrations for all apps

Check once whether you have included the app name in INSTALLED_APPS in settings.py

Related

How to run a cloned Django project with only a `mysite/settings.pyc` file?

This question is almost the same as How to run cloned Django project? but because this project only includes mysite/settings.pyc, even the most basic commands fail in reference to Django settings.
$ python3 manage.py runserver
...
ImportError: bad magic number in 'mysite.settings': b'\x03\xf3\r\n'
$ django-admin runserver --settings=mysite.settings
...
ModuleNotFoundError: No module named 'mysite'
Trying other commands (e.g., python3 manage.py migrate) fail with reference to the bad magic number in mysite.settings.
The thread How to run a Django project with .pyc files without using source codes? seems to be exactly about this topic, but (1) the project is already structured as advised, and (2) that person answered their own question so they may tried that in the same dev environment.
This answer in the ImportError: bad magic number in 'time': b'\x03\xf3\r\n' in Django thread suggests that there are bytecode-only releases (yeah, I'm new to Python) so am I missing something? (The rest of the answers are not applicable in my case as deleting all pyc files would include deleting the settings.pyc as well... This post on pyc bytecode files was elucidating though.)
The DJANGO_SETTINGS_MODULE environment variable is also properly set up (1, 2), and in this case it seems that the mysite.settings module is simply missing.
Just in case this is relevant: I'm on NixOS so set up the Python3 environment with mach-nix.

Pycharm can't find Django app 'users' when running tests

I was handed a project which uses Django and Docker, but when I run Django tests Pycharm always seems to have problem finding the users application. Other people in the project have it running without problems but even though we tried to copy their settings, it wouldn't work. I also downgraded to their exact Pycharm version without success. What could be wrong?
I have Docker desktop running without any problem. It's able to create containers and all that. I've also included it in Pycharm with success.
I've also created an interpreter through Docker-compose with a valid .yml file. This file is my colleagues.
I've of course added it as my project interpreter.
I've set up a Django test configuration with appropriate interpreter and with an empty target field so that all applications in INSTALLED_APPS are run, as per documentation.
Still, the module 'users' cannot be found. Passing in DJANGO_SETTINGS_MODULE=config.settings.local to the test configuration yields the same error.
However, when I run from the terminal, all works as expected.
What might be the problem here?
I was using the modern django setup (generated from cookiecutter-django) which Pycharm seems to have trouble with. By right-clicking the folder and choosing "Mark directory as" and marking my project directory as "Sources Root" (i.e. the project/project folder), Pycharm was able to run it properly.
Did you try unchecking options related to PYTHONPATH in your run configuration?
It may override your modules path and cause such mess with finding them.

Django - Built project broken

So basically, I have a DJANGO project that can be executed and work well. And I don't know why (maybe I upgrade my django or sth) that this is no longer working.
First I try "python3 manage.py runserver" I get this from console:
So I try to collect the static file with "python3 manage.py collectstatic"
And I do have "ckeditor" in my static folder
And I'm sure that my project is work because it still online somewhere.
And notice 1 thing that in the project that my "manage.py" is not turning red. like this
I know its just UI behavior but it seems that the project is broken. Anyone has idea bout it?
It seems to me that you've got a python dependency problem. You've probably added django ckeditor in your INSTALLED_APPS settings, but it's not installed in your (virtual) env.
So have you installed django ckeditor using pip ? It's not related to the static folders or anything, they're not compile time errors. They are 404s.

Django 1.4 Unknown command: 'runserver'

Something in my python path must have changed because now I cannot run the.
python app/manage.py runserver
The output I get is
Unknown command: 'runserver'
Type 'manage.py help' for usage.
I've looked at my environment's PYTHONPATH and PATH variables, but I can't figure out why its not running.
I've found the answer to my question.
If you've got an error in your settings, manage.py will swallow the exception and report as if the command does not exist.
This lead me down the path of incorrectly assuming my python path or venv environment was messed up.
If you want to diagnose this issue, run...
python app/manage.py help
... and it will show the exception. This, of course, was what was recommended by the django shell after it had told me that the command was not found.
This is clearly a bug in Django 1.4. It seems to me, an Exception should be reported regardless of what management command you run.
Looking through the manager.py code and django.core.management I can come up with some suggestions.
First, check if the file <some_path>/django/core/management/commands/runserver.py exists.
Second, run:
>>> import sys
>>> sys.path
If the aforementioned <some_path> is not in this list than you must set the PYTHONPATH variable.
Third, (and that's the longest of all shots) if you have changed the DEFAULT_PORT of runserver, try changing it back to 8000.
I agreed with OP. I met the same problem, and it turned out to be an error in settings.py:
In settings.py I use os.environ[something] and those environment variables are loaded in apache start script. If I run manage.py from the command line, it doesn't know what is os.environ[something] thus error occurs.
So for anyone here searching for solution, suggestion is to check circumstance difference between running django project and pure manage.py, maybe you'll find what's wrong.
I will add my answer to the same problem I had. This was unrelated from Django version, but in an old instance of my project I was providing my own Django copy and not installing from pip. Later I decided to use Pip installed Django.
When I pulled the changes on the server, my repo's copy of Django files were deleted but not the .pyc files. manage.py would still import the old .pyc files making the imports break half way and the error was the same "Unknown command: runserver".
Naturally, fully deleting the folder with the .pyc files fixed the problem.

Django Error: Could not import settings 'interfaces.settings'

So, I'm fairly new to programming. I have relatively little background in django and don't understand much of its implementation. However I have read through django tutorials and have a basic understanding of the underlying structure.
So currently I am not actually modifying the django project being used by the server (lets call it /main), I think my coworker copied over the project to a new directory called /test. When I try to do anything with manage.py located in the /test directory by running
python2.4 manage.py runserver
I get an error saying
Django Error: Could not import settings 'interfaces.settings'
(Is it on sys.path? Does it have syntax errors?): No module named settings.
I've looked through the settings file and have tried changing main to test, but it hasn't changed anything.
Any guidance as to where I should look for a solution would be great.
Also?
It sounds like there is something hard-coded somewhere which expects the project to be in a directory called "interfaces", rather than "test". Try running manage.py shell --settings=settings, and see if that helps.
Actually, "also", you should not be editing code on the server, even if it's in a different directory to the production deployment. Install Django and the code on your local machine, and edit there.
The manage.py shell --settings=settings worked for me. I figured out from running django-admin.py runserver that settings could not be imported, because environment variable DJANGO_SETTINGS_MODULE was undefined.
Fix: export DJANGO_SETTINGS_MODULE=settings
I ran the command from the root of the project (same directory that had manage.py -- not sure if it matters). Then, running manage.py shell worked without the --settings=settings bit.
Cheers!
Try to undestand which versions of python you have installed.
Type python2 and press tab button in console.
It looks, that you are trying to run version of python, which has not django installed in libs.
Also try to run python2.4 in interactive mode from test folder and import settings.

Categories

Resources