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

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

  •  21-06-2022
  •  | 
  •  

Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top