I'm trying to connect to a SAP SQL Anywhere database with pyodbc and the FreeTDS ODBC driver.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'mssql_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.65.1.20',
'PORT': '1433',
'OPTIONS': {
'driver': 'FreeTDS',
'host_is_server': True,
},
},
'sybase_database': {
'ENGINE': 'django_pyodbc',
'NAME': 'blabla',
'USER': 'blabla',
'PASSWORD': 'blabla',
'HOST': '10.60.1.6',
'PORT': '2638',
'OPTIONS': {
'driver': 'FreeTDS',
'host_is_server': True,
},
},
}
Connection to mssql_database works. But connection to sybase_database ends with this error message:
django.db.utils.DatabaseError: ('42000', "[42000] [FreeTDS][SQL Server]SQL Anywhere Error -265: Procedure 'SERVERPROPERTY' not found (504) (SQLExecDirectW)")
all traceback
$ python manage.py inspectdb --database=sybase_database
Traceback (most recent call last):
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django_pyodbc/base.py", line 491, in execute
return self.cursor.execute(sql, params)
pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]SQL Anywhere Error -265: Procedure 'SERVERPROPERTY' not found (504) (SQLExecDirectW)")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/commands/inspectdb.py", line 25, in handle
for line in self.handle_inspection(options):
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/core/management/commands/inspectdb.py", line 38, in handle_inspection
with connection.cursor() as cursor:
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django_pyodbc/base.py", line 362, in _cursor
if self.ops.sql_server_ver < 2005:
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django_pyodbc/operations.py", line 138, in _get_sql_server_ver
cur.execute("SELECT CAST(SERVERPROPERTY('ProductVersion') as varchar)")
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
File "/home/pd/packaging/venv/lib/python3.6/site-packages/django_pyodbc/base.py", line 497, in execute
raise utils.DatabaseError(*e.args)
django.db.utils.DatabaseError: ('42000', "[42000] [FreeTDS][SQL Server]SQL Anywhere Error -265: Procedure 'SERVERPROPERTY' not found (504) (SQLExecDirectW)")
$ pip list
Package Version
------------- -------
Django 1.8
django-pyodbc 1.1.3
pip 21.3.1
pyodbc 4.0.32
setuptools 59.6.0
sqlany-django 1.13
sqlanydb 1.0.11
wheel 0.37.1
When I run this script
# hello_sybase.py
import pyodbc
try:
con = pyodbc.connect('Driver={FreeTDS};'
'Server=10.60.1.6,2638;'
'Database=blabla;'
'uid=blabla;pwd=blabla')
cur = con.cursor()
cur.execute("Select * from Test")
for row in cur.fetchall():
print (row)
cur.close()
con.close()
except Exception as e:
print(str(e))
It works and prints all the rows. Is it at least possible to work with the results (rows) in a django template? It's sufficient to have read only database.
According to the site for django-pyodbc, Sybase is not supported.
The traceback leads to this code, which seems to be SQL Server specific. You'd have to hack around to make that library compatible with your database... but since you say you don't necessarily need Django's ORM stuff, you can absolutely just connect to the secondary database using the raw pyodbc layer, e.g.
import pyodbc
# TODO: move this to `settings`?
CONN_STRING = 'Driver={FreeTDS};Server=10.60.1.6,2638;Database=blabla;uid=blabla;pwd=blabla'
def my_view(request):
with pyodbc.connect(CONN_STRING) as conn:
cur = conn.cursor()
cur.execute('SELECT * FROM test')
rows = list(cur.fetchall())
return render(request, 'my_template.html', {'rows': rows})
Related
Using Django 1.11, I am attempting to create a custom router to pick a database based on the URL that is used.
For instance, if the URL is customer1.example.com, I want to pick the database 'customer1', and similarly if it is customer2.example.com, I want it to pick the database 'customer2'
My current setup works great! One problem - when I try to run migrations (or other database dependent commands), then it fails - even if I specify the database using the --database option, such as python manage.py migrate --database customer1
I'm not sure what to do, as there is no request for those - I want to actually return the exact name specified in the command line (such as customer1). But it isn't in hints, or any of the other options. How do I access the command line option that was used to run the command? Otherwise I have nothing to return!
This is my setup:
settings.py:
# Database to connect to
DATABASES = {
'default': {},
'customer1': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xxxx',
'USER': 'yyyy',
'PASSWORD': 'zzzz',
'HOST': '192.168.168.176',
'PORT': '1521',
},
'customer2': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xxxx',
'USER': 'yyyy',
'PASSWORD': 'zzzz',
'HOST': '192.168.168.179',
'PORT': '1521',
}
}
# Specify custom router
DATABASE_ROUTERS = ['workflow.router.RequestDatabaseRouter']
router.py (a custom router, uses a thread to get current request object)
from mainapp.threads import get_current_request
class RequestDatabaseRouter(object):
def db_for_read(self, model, **hints):
try:
request = get_current_request()
return request.META['HTTP_HOST'].split(':', 1)[0].split('.',1)[0]
except:
# ??????
def db_for_write(self, model, **hints):
try:
request = get_current_request()
return request.META['HTTP_HOST'].split(':', 1)[0].split('.',1)[0]
except:
# ??????
def allow_relation(self, obj1, obj2, **hints):
return True
def allow_migrate(self, db, app_label, model_name=None, **hints):
return True
I feel like something should be in the except block that just returns "whatever the --database option was in the command" - but I could not find a way to access that. Any advice?
Here is the output when I try to run the command: python manage.py migrate --database=customer1
Operations to perform:
Apply all migrations: MOC, admin, auth, contenttypes, frontend, sessions, sites, viewflow
Running migrations:
No migrations to apply.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 227, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/sql.py", line 53, in emit_post_migrate_signal
**kwargs
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/MOC/material/frontend/apps.py", line 158, in update_modules
_, created = DbModule.objects.get_or_create(label=module.label)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/query.py", line 464, in get_or_create
return self.get(**lookup), False
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/query.py", line 374, in get
num = len(clone)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/query.py", line 232, in __len__
self._fetch_all()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 876, in execute_sql
sql, params = self.as_sql()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 428, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 46, in pre_sql_setup
self.setup_query()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 37, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 227, in get_select
sql, params = self.compile(col, select_format=True)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 373, in compile
sql, params = node.as_sql(self, self.connection)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/expressions.py", line 695, in as_sql
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 364, in quote_name_unless_alias
r = self.connection.ops.quote_name(name)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/db/backends/dummy/base.py", line 20, 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.
The results of `manage.py migrate --database customer1:
{'customer1': {'PASSWORD': 'xxx', 'HOST': '192.168.168.176', 'NAME': 'mclaren', 'ENGINE': 'django.db.backends.oracle', 'PORT': '1521', 'USER': 'xxx'}, 'customer2': {'PASSWORD': 'xxx', 'HOST': '192.168.168.179', 'NAME': 'mclaren', 'ENGINE': 'django.db.backends.oracle', 'PORT': '1521', 'USER': 'xxx'}, 'default': {'PASSWORD': '', 'HOST': '', 'NAME': '', 'TIME_ZONE': None, 'USER': '', 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'OPTIONS': {}, 'PORT': '', 'TEST': {'CHARSET': None, 'MIRROR': None, 'NAME': None, 'COLLATION': None}, 'ENGINE': 'django.db.backends.dummy', 'ATOMIC_REQUESTS': False}}
The command still fails exactly as I described above. I've seen the default database get autopopulated while the site is running, but it seems to ignore whatever password I pass in. Maybe the router needs some adjustments, but I have no idea what to do with it.
Notice these lines in your stack trace:
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 227, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/core/management/sql.py", line 53, in emit_post_migrate_signal
**kwargs
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/mnt/c/cygwin64/home/chrisb/smart/python/MOC/MOC/material/frontend/apps.py", line 158, in update_modules
_, created = DbModule.objects.get_or_create(label=module.label)
Obviously, there is a post_migrate signal trying create a DbModule instance using the settings.DATBASE['default'] conf.
Which caused django.core.exceptions.ImproperlyConfigured.
I am trying to use Mongodb with in my Django.
Below there are connection settings in settings.py
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': 27017,
}
}
when I am trying to run python manage.py syncdb I am getting an error like this:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 59, in handle_noargs
tables = connection.introspection.table_names()
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 76, in table_names
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 106, in __getattr__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 133, in _connect
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1025, in __getitem__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1014, in __getattr__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/database.py", line 74, in __init__
django.core.exceptions.ImproperlyConfigured: name must be an instance of basestring
i am using django 1.3
thanks in advance
I've never used mongodb with django, but I'll take a stab just by following the trace. You need to add a value to the NAME setting in your DB configuration
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'foobar',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': 27017,
}
}
The error is being thrown here in pymongo which is created around here via django_mongo_engine
We recently pushed our site to staging and have been struggling to get it up ever since, and the team at Heroku are not really responding in time, so I am turning to the community to see if there is a quick fix.
We scrapped the old one and set up a new stack still with the same issues
heroku config
DISABLE_INJECTION: 1
settings.py
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'myuser',
'PASSWORD': 'mypassword',
'PORT': '',
'HOST': 'localhost'
},
}
Here is the full trace.
heroku run python myapp/manage.py syncdb
Traceback (most recent call last):
File "fundedbyme/manage.py", line 11, in <module>
execute_manager(settings)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/app/.heroku/venv/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 90, in handle_noargs
syncdb.Command().execute(**options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
cursor = connection.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init__.py", line 252, in cursor
cursor = util.CursorWrapper(self._cursor(), self)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 140, in _cursor
self.connection = Database.connect(**conn_params)
File "/app/.heroku/venv/lib/python2.7/site-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 5432?
DATABASES = {
'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}
Make sure you have Postgres on your heroku:
heroku addons:add heroku-postgresql:dev
Figure out database url env variable. It's going to look something like this : HEROKU_POSTGRESQL__URL
heroku config | grep POSTGRESQL
Update your settings
import dj_database_url
import os
POSTGRES_URL = "HEROKU_POSTGRESQL_<COLOR>_URL"
DATABASES = {'default': dj_database_url.config(default=os.environ[POSTGRES_URL])}
Bob is your uncle.
I put together a handy bootstrap for django on heroku. It might be helpful: https://github.com/callmephilip/django-heroku-bootstrap
Happy deploying
Try this:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://myuser:mypassword#localhost:5432/mydb')}
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.