I've setup my settings.py as follows :
{{{#!python
DATABASE_ROUTERS = ['engine.db.routers.custom.Router',]
}}}
The path to the router is fine, because changing it to a non-existing one
raises a correct error. The router inherits from object, and defines the 4
functions shown in the Django documentation. The
{{{allow_relation}}} and {{{allow_syncdb}}} members return True (tried
with None), {{{db_for_write}}} and {{{db_for_read}}} return a database
name or None.
I have properly defined my {{{DATABASE}}} setting.
However, trying to syncdb throws
{{{
File "/home/artscoop/virtualenv/project/lib/python2.7/site-
packages/django/db/__init__.py", line 16, in <module>
router = ConnectionRouter(settings.DATABASE_ROUTERS)
File "/home/artscoop/virtualenv/project/lib/python2.7/site-
packages/django/db/utils.py", line 117, in __init__
raise ImproperlyConfigured('Error importing database router %s: "%s"'
% (klass_name, e))
django.core.exceptions.ImproperlyConfigured: Error importing database
router Router: "cannot import name connection"
}}}
No answer in any site could resolve this problem.
The dubious advice to add {{{from django.db import connections}}} leads to
another exception
{{{
File "/home/steve/virtualenv/project/lib/python2.7/site-
packages/django/db/backends/dummy/base.py", line 15, 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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20704>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
I have found that moving the router to a file in the project root fixes
everything. But the problem with importing from another location is still
a bug.
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:1>
Comment (by aaugustin):
Looks like a circular import.
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:2>
Comment (by charettes):
@artscoop what are you importing in your routers module?
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:3>
Comment (by claudep):
This might have been fixed by commit [6a6bb168be90594a18]. To check this,
it would be nice if you could test with the current 1.6beta.
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:4>
Comment (by artscoop):
The routers.py module does not import anything.
Only has
{{{#!python
# coding: utf-8
from __future__ import absolute_import
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:5>
Comment (by artscoop):
The behaviour of routers seems correct in 1.6b1 though. (the only problem
there is with fixtures)
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:6>
* status: new => closed
* resolution: => worksforme
Comment:
Thanks for testing on latest code, and I'm happy this is fixed there.
I think you should be able to temporarily workaround the problem by moving
your custom Router class in a different path. The current circular import
issue may be caused by any `__init__.py` along the path (i.e.
`engine/__init__.py`, `engine/db/__init__.py`, etc.).
I really doubt that the fix will be backported in 1.5, therefore closing
the ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/20704#comment:7>