A
A
Anton2018-09-24 05:51:25
Django
Anton, 2018-09-24 05:51:25

How does Django access the second database?

Something in my head doesn’t fit how I can access an existing one from under Django (that is, a second or separate database). let's say there is a main site database (which Django created automatically) db.sqlite3.sqlite3? in settings it is written like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },

But I want to get some data from the second database, called: BDtest.db
For this, I registered it in settings:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'CSDNbd': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'BDtest'),
    }
}

How can I retrieve data from an already existing table? Especially if it is not default ...
After all, when I create a model in models.py, then immediately a new table is created, especially since a simple call involves accessing the default database, or am I not understanding correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question