📜 ⬆️ ⬇️

Django multiple database support - now supports multiple database connections

All twitter literally boils from this news - django now supports multiple database connections. The feature is embedded in the trunk and described in the documentation .

The documentation (via the link above) describes the process of setting up and using several databases in django:


# in settings.py:
')
DATABASES = {
'default': {
'NAME': 'app_data',
'BACKEND': 'django.db.backends.postgres_psycopg2',
'USER': 'postgres_user',
'PASSWORD': 's3krit'
},
'users': {
'NAME': 'user_data'
'BACKEND': 'django.db.backends.mysql',
'USER': 'mysql_user',
'PASSWORD': 'priv4te'
}
}


# in model lookups:

Author.objects.using('default').all()


# using ('default') - explicitly specifying the database for the request. If you do not specify will take default

See the documentation for more details! Congratulations to all with this new feature, we have long been waiting for this functionality. Hooray!

Source: https://habr.com/ru/post/79062/


All Articles