I'm having a hard time because my django project.
Who can help?
I'd like to thank you for your help.
set .env in proeject Root path
SECRET_KEY=exampleKey
DEBUG=False
DB_ENGINE=django.db.backends.mysql
DB_NAME=example
DB_USER=admin
...Blah Blah
project settings.py
import os
import environ
env = environ.Env(DEBUG=(bool, False), )
environ.Env.read_env()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = env('SECRET_KEY')
DEBUG = env('DEBUG')
...Blah Blah
And when run the project
I get an this error message.
Django_workspace/asone/asone/.env doesn't exist - if you're not configuring your environment separately, create one.
"environment separately, create one." % env_file)
raise KeyError(key) from None
KeyError: 'SECRET_KEY'
During handling of the above exception, another exception occurred:
/Django_workspace/asone/venv/lib/python3.7/site-packages/environ/environ.py", line 277, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
I have a hard time because I'm a django beginner.
Who can help? I'd like to thank you for your help.
.P.S
Thank you so much for your answer.
I'm sorry. I'm telling you, there's something I missed out on.
I set up a django-environ package to use the .env in the project.
pip install django-environ
Is there something I'm missing?
What more information will be needed to solve this problem?
.P.S
set up python-dotenv package
pip install python-dotenv.
Change settings.py
import os
from dotenv import load_dotenv
load_dotenv()
...
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG=os.getenv('DEBUG')
DATABASES = {
'default': {
# 'ENGINE': env('DB_ENGINE'),
# 'NAME': env('DB_NAME'),
# 'USER': env('DB_USER'),
# 'PASSWORD': env('DB_PASSWORD'),
# 'HOST': env('DB_HOST'),
# 'PORT': env('DB_PORT'),
'ENGINE': os.getenv('DB_ENGINE'),
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
}
}
...
and then I met this error message.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 562, in configure
handler = self.configure_handler(handlers[name])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 735, in configure_handler
result = factory(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py", line 148, in __init__
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/handlers.py", line 55, in __init__
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1087, in __init__
StreamHandler.__init__(self, self._open())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1116, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/logs/logfile'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/haemil/Desktop/Back-end workspace/Django_workspace/asone/venv/lib/python3.7/site-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 799, in dictConfig
dictConfigClass(config).configure()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/config.py", line 570, in configure
'%r' % name) from e
ValueError: Unable to configure handler 'file'
Is there something I'm missing?
There is no environ module in stdlib(standard library of python). So I checked if there is third party module called 'environ' by running pip install environ, which installed it, but when I checked at pypi website, I can't see any valid explanation. I think it's not maintained well.
So I concluded that your environ configuration went a bit odd.
Here's my suggestion
Install python-dotenv module by running pip install python-dotenv. There are many .env module, but this is one of the most popular, well maintained one in my opinion.
Ensure your .env file is in the directory where settings.py is. setting.py will load .env file in the same directory unless specified otherwise
Change your code from this
import os
import environ
env = environ.Env(DEBUG=(bool, False), )
environ.Env.read_env()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = env('SECRET_KEY')
DEBUG = env('DEBUG')
to this
import os
from dotenv import load_dotenv
load_dotenv()
...
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG=os.getenv('DEBUG')
...
Change your db setting similar way
DATABASES = {
'default': {
'ENGINE': os.getenv('DB_ENGINE'),
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
# and so on ...
}
}
}
You are running into a KeyError because either:
You aren't putting a SECRET_KEY variable in your .env file.
It can't find your .env file.
From what I can see from your answer, try moving your .env file from your root directory to where it will sit alongside settings.py.
Related
I'm setting GitHub source ↓
https://github.com/priyankavergadia/Django-Dialogflow-GoogleVisionAPI
But I have trouble in [Deploy the app to the App Engine standard environment] phase.
At a glance Deploying have been done well.But I'm trying to access webservice, so [502 Bad Gateway] appears.
At local environment(running python manage.py runserver), this program works well.
Please give me some advices.
My environment:
Windows10
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
django 2.2.4
MySQL second generation 5.7
mysql django
I serched and tried to:
install mysqlclient and uninstall PyMySQL
rewrite [import ~]part in various pattern...
description in Django setting.py below
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter
# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
# for more information
import MySQLdb as sql# noqa: 402
# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/michatbot-250809:us-central1:polls-instance2',
'USER': 'test',
'PASSWORD': '',
'NAME': 'polls',
}
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
# $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': 'polls',
'USER': 'test',
'PASSWORD': '',
}
}
# [END db_setup]
eroor log on Google App Engine below
textPayload: "Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
super(ThreadWorker, self).init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/srv/main.py", line 1, in <module>
from mysite.wsgi import application
File "/srv/mysite/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/srv/mysite/settings.py", line 82, in <module>
import MySQLdb as sql # noqa: 402
ModuleNotFoundError: No module named 'MySQLdb'"
There are two threads where the community figured out several ways to solve this error depending on your SO and software's versions. You can refer to these threads, second one, and also to this one that addresses discussion more about connecting MySQL in Python 3 on Windows.
Make sure to follow the documentation about Python 3.7 in the GAE Standard. Also, GAE has some specific support for using Django, I'd suggest going through the Django Support documentation and Django App example.
I am running a gitlab CI for my django project with Mysql DB.
And I am getting following error :
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
My requirement.txt file is as follows :
Django==2.0.4
django-extensions==2.0.6
mysqlclient==1.3.12
Here is My CI Config file:
# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python
image: python:latest
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
services:
- mysql:latest
# - postgres:latest
variables:
# POSTGRES_DB: database_name
MYSQL_DB: database_name
MYSQL_ALLOW_EMPTY_PASSWORD: "1"
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- ~/.cache/pip/
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
- python -V
# Print out python version for debugging
# Uncomment next line if your Django app needs a JS runtime:
# - apt-get update -q && apt-get install nodejs -yqq
- pip install -r requirements.txt
# To get Django tests to work you may need to create a settings file using
# the following DATABASES:
#
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'ci',
# 'USER': 'postgres',
# 'PASSWORD': 'postgres',
# 'HOST': 'postgres',
# 'PORT': '5432',
# },
# }
#
# and then adding `--settings app.settings.ci` (or similar) to the test command
test:
variables:
# DATABASE_URL: "postgresql://postgres:postgres#postgres:5432/$POSTGRES_DB"
MYSQL_ALLOW_EMPTY_PASSWORD: "1"
DATABASE_URL: mysql://root#mysql:3306
script:
- python manage.py test
And the whole output is:
Running with gitlab-runner 10.7.0-rc1 (a4699306)
on docker-auto-scale 4e4528ca
Using Docker executor with image python:latest ...
Starting service mysql:latest ...
Pulling docker image mysql:latest ...
Using docker image sha256:8d65ec712c69a27e2b9064f2fef307849775687d270e9ab5b79fd17dcd31b16e for mysql:latest ...
Waiting for services to be up and running...
Pulling docker image python:latest ...
Using docker image sha256:6bf7a4fa2d455fae4ce7f38b0b6db33fc5c5ea537c252b0bab8a6338176cb81b for python:latest ...
Running on runner-4e4528ca-project-4802656-concurrent-0 via runner-4e4528ca-srm-1524305095-4dc1df06...
Cloning repository...
Cloning into '/builds/dptks19/..._devel'...
Checking out 3062aac8 as master...
Skipping Git submodules setup
Checking cache for default...
FATAL: file does not exist
Failed to extract cache
$ python -V
Python 3.6.5
$ pip install -r requirements.txt
Collecting Django==2.0.4 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/89/f9/94c20658f0cdecc2b6607811e2c0bb042408a51f589e5ad0cb0eac3236a1/Django-2.0.4-py3-none-any.whl (7.1MB)
Collecting django-extensions==2.0.6 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/1e/0e/1a5184f7adbd2d28c8329cffd3806c036901d2a6e790c058fc70259bd4da/django_extensions-2.0.6-py2.py3-none-any.whl (217kB)
Collecting mysqlclient==1.3.12 (from -r requirements.txt (line 3))
Downloading https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz (89kB)
Collecting pytz (from Django==2.0.4->-r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
Collecting six>=1.2 (from django-extensions==2.0.6->-r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Building wheels for collected packages: mysqlclient
Running setup.py bdist_wheel for mysqlclient: started
Running setup.py bdist_wheel for mysqlclient: finished with status 'done'
Stored in directory: /root/.cache/pip/wheels/50/c7/31/81a516762c8e9324f2b1fdffc1e84b9f07224fe3707956f6e1
Successfully built mysqlclient
Installing collected packages: pytz, Django, six, django-extensions, mysqlclient
Successfully installed Django-2.0.4 django-extensions-2.0.6 mysqlclient-1.3.12 pytz-2018.4 six-1.11.0
$ python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 236, in get_new_connection
return Database.connect(**conn_params)
File "/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 59, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/local/lib/python3.6/site-packages/django/test/runner.py", line 601, in run_tests
old_config = self.setup_databases()
File "/usr/local/lib/python3.6/site-packages/django/test/runner.py", line 548, in setup_databases
self.parallel, **kwargs
File "/usr/local/lib/python3.6/site-packages/django/test/utils.py", line 176, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 54, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 164, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 236, in get_new_connection
return Database.connect(**conn_params)
File "/usr/local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
ERROR: Job failed: exit code 1
I am trying to run my django project with mysql, locally it is running fine, but when I push any of my code it failes in CI stage.
Any one, what goes wrong?
EDIT:
Settings.py
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'some_db_devel_2',
'USER': 'root',
'PASSWORD': '******',
'HOST': '',
'PORT': '',
}
}
I hoping that you can help me out. I currently have Django1.7 running on windows7/Java7/Jython2.7/Postgresql9.3/postgresql-9.3-1102.jdbc41.
For more details about django on jython and the database settings.
postgresql on jython-django
My settings are:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'lwc',
'USER': 'lwc',
'PASSWORD': 'lwc',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
My Question:
I am not able to install South by using pip. So, I just installed it manually from the source. Afterwards I do jython manage.py syncdb
I then get an error... Do you have any ideas how to resolve this error?
C:\Users\michmar3\workspace\lwc>jython manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 354, in execute
django.setup()
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\__init__.
py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\apps\regi
stry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\apps\conf
ig.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "C:\jython2.7b2\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\jython2.7b2\Lib\site-packages\south-1.0-py2.7.egg\south\models.py", l
ine 2, in <module>
from south.db import DEFAULT_DB_ALIAS
File "C:\jython2.7b2\Lib\site-packages\south-1.0-py2.7.egg\south\db\__init__.p
y", line 84, in <module>
db = dbs[DEFAULT_DB_ALIAS]
KeyError: 'default'
south will not work with django 1.7. http://south.aeracode.org/
The functionality that south used to provide has been directly merged into django with the 1.7 release.
See the django documentation for how to use the django migration support that replaces south. https://docs.djangoproject.com/en/1.7/topics/migrations/
I have made my searchings but found no answer. Please help!
This is what I do:
(holistic)chris#notebook:~/workspace$ django-admin --version
1.4
(holistic)chris#notebook:~/workspace$ django-admin startproject holistc
(holistic)chris#notebook:~/workspace$ cd holistc/
(holistic)chris#notebook:~/workspace/holistc$ vim settings.py
(holistic)chris#notebook:~/workspace/holistc$ python manage.py startapp main
(holistic)chris#notebook:~/workspace/holistc$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/home/chris/.virtualenvs/holistic/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
and this is my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'holistic_db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
any ideas whould be appreciated.
Thanks.
In django 1.4 the path of the settings file would be workspace/holistc/holistc/settings.py.
This is different from previous versions of django. You can read about the new project layout here.
In attempting to run ./manage.py runserver or shell or any other command for that matter, I'm getting the error: You must define a 'default' database.
I'm running this in a virtualenv and settings.py includes DATABASE_NAME, along with Host, Port and Engine. Where is django expecting definition of the default database?
Here's the traceback:
(env)fox-ser01:common wmfox3$ ./manage.py shell
Traceback (most recent call last):
File "./manage.py", line 31, in <module>
execute_manager(settings)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/db/__init__.py", line 12, in <module>
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
django.core.exceptions.ImproperlyConfigured: You must define a 'default' database
DATABASE_NAME is deprecated since django 1.2 so if you're using newer version, you should use the new way of defining databases:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
define db name is settings.py
DATABASE
Below is an example
DATABASES = {
'default': {
'ENGINE': 'mysql',
'NAME': 'xyz', # db name
'USER': 'root',
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
In settings.DATABASES.