29
It might be that django is not accessing the settings.py file you think it uses.
Try explicitly point django to your settings file by using –settings
./manage.py --settings=nameofproject.settings runserver/syncdb
If this works then, you’ll have to figure out why django is importing the wrong settings file.
Have you upgraded from 1.3 to 1.4 by accident ?
17
For me, I had a similar problem with django 1.6 just now:
BACKGROUND
Django 1.6 heroku project using Heroku Postgresql database
I wanted to develop directly on the postgresql server (so don’t copy the “.postgresql_psycopg2” bit if you’re not also using postgresql)
- No problem developing using the local psql db
-
Got that error when I uncommented the line to use heroku db
DATABASES['default'] = dj_database_url.config(default=os.getenv('DATABASE_URL'))
Initial attempt was to add more details, such as another line,
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
This didn’t work though, because then the error asked me for NAME, which it rejected.
SOLUTION
In the end, this solved it:
-
I ran “heroku config” to see my details presented to me in the format:
postgres://user:pass@localhost/dbname
-
I updated the settings.py file to reflect those details:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'your_heroku_db_name', 'USER': 'your_heroku_db_user_name', 'PASSWORD': 'your_heroku_password', 'HOST': 'ec2-23-21-133-106.compute-1.amazonaws.com', # Or something like this 'PORT': '5432', } }
That tip is from https://stackoverflow.com/a/19719966/870121
Note: my next plan is to abstract these back into .env variables rather than leaving them visible in settings.py
-
I then commented out the later line,
# DATABASES['default'] = dj_database_url.config(default=os.getenv('DATABASE_URL'))
so DATABASES was only specified once in the settings.py file
That way the program read everything required to connect to the postgresql heroku db
e.g., now
python manage.py syncdb
is working for me
If you want to try developing locally, comment out everything above and instead set your local postgresql server going and uncomment the local equivalent of the above:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cool01db',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost', # '127.0.0.1' probably works also
'PORT': '5432',
}
}
That’s from https://stackoverflow.com/a/25962586/870121
- [Django]-How to move a model between two Django apps (Django 1.7)
- [Django]-Django-tables2: How to use accessor to bring in foreign columns?
- [Django]-How to save a model without sending a signal?
6
There are two ‘settings.py’ files in your project(if your OS is UNIX-like):
- One is in the first dir
- One is in the dir/dir
You need to write the ENGINE to the second (dir/dir/setting.py
).
Good luck!
- [Django]-Django – Simple custom template tag example
- [Django]-How to debug in Django, the good way?
- [Django]-Django persistent database connection
3
Which settings.py file have you updated? I had this exact same problem at first too when I didn’t read about Django’s changes from 1.3 to 1.4 which causes double imports. Here is an excerpt from https://docs.djangoproject.com/en/1.4/releases/1.4/#updated-default-project-layout-and-manage-py. The latest version of Django (currently 1.4.2) ships with an updated default project layout and manage.py file for the startproject management command and the default project layout has changed.
To fix your error, the correct settings.py file you should use is NOT the one in the main project directory, it is the one inside the directory that is created inside the project directory (with the same name).
- [Django]-Django: dependencies reference nonexistent parent node
- [Django]-Django Error u"'polls" is not a registered namespace
- [Django]-Memory efficient (constant) and speed optimized iteration over a large table in Django
0
Re-installing Django did the trick for me(actually removing the egg file),as suggested in the following link.
https://code.djangoproject.com/ticket/18058
It seems that upgrading from 1.3 to 1.4 seems to cause a lot of these problems.
- [Django]-Expire a view-cache in Django?
- [Django]-Vim, Python, and Django autocompletion (pysmell?)
- [Django]-Using django-rest-interface