Django: How to disable checking the status of the database on startup?
As far as I know, Django apps cannot start if any of the databases installed in settings.py
are at the beginning of the app. Is there anyway to make Django "lazyload" the original database connection?
I have two databases configured, and one of them is a bit unstable and sometimes it might not be available for a few seconds, but it is only used for some specific use cases of the application. As you can imagine, I don't want the whole application to be unable to start because of this. Is there any solution for this?
I am using Django 1.6.11 and we are also using Django South for database migrations (in case it is related in one way or another).
source to share
I did some more tests and the problem only occurs when using the development server python manage.py runserver
. In this case, it forces a connection to the database.
Using a real WSGI server is not happening as reported by @Alasdair.
@JohnMoutafis, in the end I haven't tested your solution, but it might have worked.
source to share
I don't know how safe it is, but you can do the following:
-
The
settings.py
start from scratchDATABASES
:DATABASES = {}
-
In yours,
apps.py
use a hookready()
to establish database connections:from settings.py import DATABASES class YourAppConfig(AppConfig): def ready(self): DATABASES.update({ Your database connections })
Now I can't put my hand behind the fire for this, but Django will try to re-initialize the database connection when needed.
source to share