Loading from multiple databases in Django custom command -



Loading from multiple databases in Django custom command -

if creating django custom command, can info more 1 database? in c:/project/myproject/settings.py, have:

databases = { 'default': { 'engine': 'django.db.backends.sqlite3', 'name': os.path.join(base_dir, 'db.sqlite3'), } }

then in c:/project/myproject/myapp/management/commands/mycommand.py, have:

users = user.objects.all()

where user defined in c:/project/myapp/models.py.

but if have several databases, called db1.sqlite3, db2.sqlite3, db3.sqlite3 etc., , want load user objects these databases in custom command? possible?

from the documentation:

you can select database queryset @ point in queryset “chain.” phone call using() on queryset queryset uses specified database.

you define more databases in settings.py, give them names , pass name using('db_name').

django

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -