#27285 closed Uncategorized (duplicate)
Multi-db example : default database config can not be an empty dict
| Reported by: | Jose M Herrero | Owned by: | nobody |
|---|---|---|---|
| Component: | Documentation | Version: | 1.10 |
| Severity: | Normal | Keywords: | multi-db dbrouter |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I have the same problem as ticket #26955 that is closed, documentation https://docs.djangoproject.com/es/1.10/topics/db/multi-db/ says default database can be left empty but then tests fails.
To reproduce with nothing interfering I started a fresh project, these are the steps to reproduce:
- Start a new Django 1.10.1 project with
django-admin startproject mysiteand cd into itcd mysite - Create a database router
mysite/dbrouter.pyCode highlighting:
class DbRouter(object): def db_for_read(self, model, **hints): return 'master' def db_for_write(self, model, **hints): return 'master' def allow_relation(self, obj1, obj2, **hints): return True def allow_migrate(self, db, app_label, model_name=None, **hints): return True
- Edit
mysite.settings.pyas doc says with empty default and set the database router
Code highlighting:
DATABASES = { 'default': {}, 'master': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }, } DATABASE_ROUTERS = ['mysite.dbrouter.DbRouter']
- Create
mysite/tests.pyCode highlighting:
from django.test import TestCase class SurveyFormTest(TestCase): def test_sample(self): print 'hello'
- Execute the tests and bang!
python manage.py test mysite
Creating test database for alias 'master'...
hello
.E
======================================================================
ERROR: test_sample (mysite.tests.SurveyFormTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/test/testcases.py", line 216, in __call__
self._post_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/test/testcases.py", line 908, in _post_teardown
self._fixture_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1060, in _fixture_teardown
return super(TestCase, self)._fixture_teardown()
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/test/testcases.py", line 943, in _fixture_teardown
inhibit_post_migrate=inhibit_post_migrate)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 130, in call_command
return command.execute(*args, **defaults)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/core/management/commands/flush.py", line 54, in handle
allow_cascade=allow_cascade)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/core/management/sql.py", line 15, in sql_flush
tables = connection.introspection.django_table_names(only_existing=True, include_views=False)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 88, in django_table_names
existing_tables = self.table_names(include_views=include_views)
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 55, in table_names
with self.connection.cursor() as cursor:
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor
cursor = self.make_cursor(self._cursor())
File "/home/chemary/workspace/myvirtualenv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 21, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
Destroying test database for alias 'master'...
Change History (6)
comment:1 by , 9 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
It does no make any difference, I verified that Django was calling allow_migrate.
comment:5 by , 9 years ago
| Component: | Documentation → Testing framework |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Type: | Uncategorized → Bug |
Duplicate of #25504.
comment:6 by , 9 years ago
| Component: | Testing framework → Documentation |
|---|---|
| Type: | Bug → Uncategorized |
Same problem with multi_db=True. Sorry for issuing a duplicate ticket, I didn't found it before.
Does it make a difference if
DbRouter.allow_migrate()returnsFalsefor'default'?