Django 1.5 : 'Error importing database router' that was previously importing correctly

StackOverflow https://stackoverflow.com/questions/18024047

  •  21-06-2022
  •  | 
  •  

문제

I'm running Django 1.5 for the last several weeks developing an app with multiple databases. I set up a router for a separate database an placed it under routers.py in my project directory in settings I made sure to add the path to the router the way the django documentation dictates:

# Extra Database Routing modules
DATABASE_ROUTERS = ['myapp.routers.MyRouter']

And that worked. For the last 2 weeks there have been no issues. Now, randomly after I saved my models.py file after taking out an from djanog.conf import settings that was not being used, I got this on my development server after running python manage.py runserver:

Validating models...

0 errors found
August 02, 2013 - 16:12:42
Django version 1.5.1, using settings 'app.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
ImproperlyConfigured: Error importing database router MyRouter: "cannot import name connection"

Note that it validated all the models before erroring. Which didn't make any sense to me. I went to these places seeking an answer

The attempts at importing connections with from django.db import connections inside my settings file, resulting in causing an ImproperlyConfigured: The SECRET_KEY setting must not be empty. That's simply because when importing connections it also imports everything inside the django.db __init__.py which includes from django.conf import settings which then overwrites the settings I already had. (or at least I believe that's what's happening) Point being is that something is happening which I don't fully understand.

Can anyone shed some light on why suddenly my router would be unable to be imported?

도움이 되었습니까?

해결책

After some few hours of powering over the core django files there appears to be a circular import which is actually a bug inside the Django framework that is fixed for 1.6: here's the ticket <code.djangoproject.com/ticket/20704>; Moving my routers.py containing my custom router which was in my project directory to a different module (I used the app module which doesn't have any init.py file) made everything run correctly again. Hope this saves some one some headaches.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top