Django South problem in Aptana - django

I try to add South migration tool to my Django app. I installed South by running python setup.py install and it is installed successfully. Now I can run migrate appname and schemamigration appname --auto commands and they work great.
However, after I run migration appname, it created migration package under my app folder and created a init.py. There are such imports in this init file
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
Although everything works perfect, from south.db and from south.v2 lines give error in Aptana which is about it cannot import these files.
Do you have any idea why it happens ? Should I add the location of south folder to any system path ?
Thanks

Have you added the parent directory where south was installed (site-pacakges, or maybe a virtualenv's site-packages) folder to your Project's pythonpath?
You'll need to set your project as either a PyDev project or Django project.
Right-click on your project, choose the correct nature.
Then right-click again and go to Properties.
Choose the PyDev-PYTHONPATH setting and click on External Libraries.
Click Add source folder, nav to the parent of the module you want to add to the path and hit either apply or OK, depending on how many folders you want to add to the project's pythonpath.
Hope that helps you out.

Related

Create migrations for models inside egg dependency

I have a Django project that itself does not have apps. All apps come in through egg dependencies installed in a pyvenv environment.
Those apps have models but do not have 'manage.py' or database settings (just a plain app).
I am now struggling to create the migrations for the apps in the eggs. When I execute 'python manage.py makemigrations' I get 'No changes detected' even though I wiped the DB before. When I then run the server it tells me that I have 13 unapplied migrations from Django core modules such as 'auth', 'sessions' etc. I can apply them running 'python manage.py migrate'.
I tried creating a dummy app, added it to INSTALLED_APPS and added an import of a model from an egg to models.py of that app. Didn't work either, still 'No changes detected'.
Those egg dependencies are apps I created. Is 'egg' the wrong format here? What are the alternatives? Can I tell the 'makemigrations' module where to look? What else could be the cause?
Thats because Django is looking for directories when looking for migrations. Eggs are not directories therefore will not find migrations for the apps installed as eggs.
If you tell makemigrations to do it for you, you will see an error like (on windows):
FileNotFoundError: [WinError 3] The system cannot find the path specified: C:\\path\\to\\app_egg.egg\\app\\migrations
I think the best solution is to not use eggs.

How to run manage.py in Eclipse Pydev Interactive Console

I am trying to run
manage.py to validate models (as: manage.py validate) in the Interactive Shell of a Django project (called djangonew) using Pydev
The PYTHONPATH is set to include /djangonew ... so import djangonew and then dir(djangonew) actually gives me a name as 'settings' in the subfolder /djangonew/djangonew
but at the command-line I am unable run manage.py (and even find it)
How do I solve this issue? Thanks much
right click on project, open menu django-> custom command
and type verify ( or other command after "manage.py")

Cannot start any django app

I am a newbie at Django and everytime I try to run
python panel/manage.py startapp %app% (panel is my project) it gives me the error:
Error: '%app%' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
Am I doing something wrong?
Surely companies or contacts or stats is not the name of an existing Python module?
This is a fun one - your project and your app need to have different names. You probably created a project, then tried to startapp with the same name.
I was confused as well, until I realized that a Django project is a container for applications; this sequence makes it a bit clearer:
# first create a Project (container).
django-admin.py startproject Project
# create multiple apps
cd Project
python manage.py startapp polls
python manage.py startapp hello
...
Perhaps you need to
cd panel
python manage.py startapp yourappname
I'm not sure running the command from a directory above your project will work properly.
I had the same issue because I was trying to "restart" my app after carrying out changes, but startapp is meant to be used once to create a new app. To view changes, syncronize app with DB with python manage.py migrate and restart the server with python manage.py runserver instead.
From the django-admin docs
(manage.py does essentially the same thing as django-admin)
startapp <app_label> [destination]
django-admin startapp
Creates a Django app directory structure for
the given app name in the current directory or the given destination.
By default the directory created contains a models.py file and other
app template files. (See the source for more details.) If only the app
name is given, the app directory will be created in the current
working directory.
If the optional destination is provided, Django will use that existing
directory rather than creating a new one. You can use ‘.’ to denote
the current working directory.
For example:
django-admin startapp myapp /Users/jezdez/Code/myapp
This message is displayed if you run "startapp" twice with the same app name. As pointed out above by the OP it doesn't reload the app, it creates one.
You should choose different names for your project and app in Codes:
django-admin startproject **my_project**
python manage.py startapp **my_app**
You need to create the directory before using the commands. Suppose you want a polls app inside apps folder.
mkdir apps apps/polls
python manage.py startapp polls apps/polls
I guess maybe you have already created the app's dir in panel dir manually. The command 'startapp' is to create an app automatically. If you already have one there, it fails.
I reproduced the issue and there's actually something not working as I expected.
I wonder if we stumbled upon a Django's bug, or a limitation that I don't understand.
Having a project called "project" and an empty folder app/newapp
…I tried:
python manage.py startapp newapp apps/newapp
It returns:
CommandError: 'newapp' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
But if I target ANY other route in which the last folder is not called the same name as the app I'm starting, it works.
So I ended up doing:
python manage.py startapp newapp apps/main
Using Django 2.1.3.
if you want to make an empty directory that will contain your new app
project-dir
└── blog
├── __init__.py
├── ...
├── blog-ext #this empty dir that will contain the new app
└── views.py
so instead of typing :
python manage.py newapp blog/blog-ext
it should be :
django-admin startapp newapp blog/blog-ext
Try classic "mysite" or "myproject". You can delete it anytime you want, so if it will accepted, then all your privious ideas conflict with Python modules.
Edit: I tried all your ideas, there was no error for me. So, if you installed support libraries or modules for django, then some of them can contains such names.
this error is because of the name conflicts between the app name and project name.you had given same name for your app and project .your project and app need to be different name .if you had given the same name the above mentioned error will occur .
understand the difference between app and project
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects.
first create the project.
then create the app.
NOTE: name for app and project should be different
first create a project with projectname
django-admin.py startproject Projectname .
Then create app with appname. (to create your app make sure you are in the same directory manage.py and type this command)
python manage.py startapp Appname
It's the process how I got my doubt clear.
First, I created a directory inside my project directory and put __init__.py, models.py, admin.py, apps.py & views.py.
Then I ran python manage.py runserver & It work well.
Then as suggested on that page I used startapp command. I got this error :
CommandError: 'ucportal' conflicts with the name of an existing Python
module and cannot be used as an app name. Please try another name.
After that I deleted that directory and ran startapp command with same name and it worked fine.
So 'startapp' command is to create an app automatically. If you already have one there, it fails.
Answer given by #DAG worked for me.
I ran into this issue while trying to set up a Wagtail project.
Before creating the app, I had created and activated a virtualenv (using virtualenvwrapper) with the same name: $APPNAME. When I then ran wagtail start $APPNAME, Django looks for naming conflics in the $PYTHONPATH which in this instance points to /Users/User/.virtualenvs.
Naturally, this results in a conflict as /Users/User/.virtualenvs/$APPNAME already exists.
None of these answers helped me. In the end I ended up creating an app with a different name and then just renaming the directory to the app name I wanted all along. Note that you also will need to change the class name in apps.py to match your app name.
Just Simply Use This command
for Django Project Creation
python -m django startproject name_of_django_Project
for Django App Creation
python -m django startapp App_name
I had the same issue when working with wagtail cms. I got this error even there is no such a created app. This occurs when there is an app already that has the same name you need to create inside the site-packages directory.
Once you get this error, you need to check the following directory,
C:\Users\{user}\AppData\Local\Programs\Python\Python38-32\Lib\site-packages
If there is a package with the name same you want to create then you need to remove that package. Also make sure to check that package is important or not before deleting.
The application directory should be created first.
Example: apps/practice
The command appears to be duplicated, but it is correct.
Example: python manage.py startapp practice ./apps1/practice

Configuration error in django

I am using django with mod_python (I know it is deprecated -- I am just doing this for an exercise), and am getting the following error --
"Could not import project.views. Error was: No module named app.models"
I am getting the 'No module named app.models" in several other places as well. My syncdb is working fine, and if I go into the manage.py shell I can import the models fine. Why is this occurring and what do I need to change? Thank you.
You should use absolute imports everywhere. If your project is structured like so:
/project/settings.py
/project/app/models.py
/project/app/views.py
In INSTALLED_APPS you would use project.app. In app you'd import your models into views: import project.app.models, etc. Alternately you can try adjusting your PYTHONPATH so your imports work. When you run ./manage.py you are in your project folder, and Python automatically adds it to the PYTHONPATH. This doesn't happen automatically in most deployment scenarios (mod_python or other wise).

Imports failing for pylint

I'm testing my project using pylint and currently getting fatal error when importing the internal apps into the project using.
According to pylint, the import should be something like from <appname>.models import ...
as opposed to what I currently have: from <projectname>.<appname>.models import My problem is that when I use the recommended style, the project can't find/import the app. What am I missing here?
Your apps are not in the python path.
Seems like you have a folder for apps, like apps/registration, apps/contact_form etc. and your manage.py is in the folder on top of that one, which has just the project folder.
manage.py does some "magic" by putting all the apps into the python path before starting the server.
If you have custom folder structure, you should edit the manage.py to include your custom apps folder in the python path, preferably as the first element of the python path.