ExamHoot

Django Database Configuration: Analyzing a multi-database setup

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'main_db',
        'USER': 'postgres',
        'PASSWORD': 'secret',
        'HOST': 'localhost',
        'PORT': '5432',
    },
    'analytics': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'analytics.db',
    }
}
  1. Two databases are configured: 'default' (PostgreSQL) and 'analytics' (SQLite). Queries use 'default' by default, but 'analytics' queries require explicit `.using('analytics')` or a database router

  2. Django automatically routes all queries to the appropriate database based on the model name

  3. The 'analytics' database will never be used because 'default' is always prioritized

  4. Both databases will be synchronized automatically whenever migrations are run

Show answer & explanation

Correct answer

Two databases are configured: 'default' (PostgreSQL) and 'analytics' (SQLite). Queries use 'default' by default, but 'analytics' queries require explicit `.using('analytics')` or a database router

Explanation

The configuration defines two databases: 'default' uses PostgreSQL for primary application data, while 'analytics' uses SQLite for analytics workload. You must use db_router or specify the database alias when querying the 'analytics' database.

Written by ExamHoot EditorialPublished · Updated

All 30 Django Project Structure and Setup questions

  1. 1.What is the primary purpose of the manage.py file in a Django project?
  2. 2.Which file in a Django project is used to store project-level settings and configurations?
  3. 3.What does the __init__.py file do in a Django app directory?
  4. 4.Which command is used to create a new Django app within a project?
  5. 5.What is the purpose of the models.py file in a Django app?
  6. 6.Where should static files like CSS and JavaScript be placed in a Django project?
  7. 7.What is the role of the urls.py file in a Django project?
  8. 8.Which file is responsible for WSGI application setup in a Django project?
  9. 9.What command should you run after creating a new Django app to register it in the project?
  10. 10.Where are HTML templates typically stored in a Django app?
  11. 11.Scenario:
  12. 12.What is the correct sequence of steps to initialize a Django project?
  13. 13.Hari is configuring a Django project with multiple databases.
  14. 14.Code-based:
  15. 15.What is the purpose of the apps.py file in a Django app?
  16. 16.Scenario:
  17. 17.Code-based:
  18. 18.What is the purpose of the admin.py file in a Django app?
  19. 19.Hari is creating a Django project with custom middleware.
  20. 20.Code-based:
  21. 21.Django Project Structure:
  22. 22.Django Project Directory Layout:
  23. 23.Django Apps and Project Configuration:
  24. 24.Settings.py Configuration:
  25. 25.Django Database Configuration:
  26. 26.Middleware Configuration:
  27. 27.Static and Media Files:
  28. 28.Environment Variables and Secret Management:
  29. 29.URL Configuration and URL Routing:
  30. 30.INSTALLED_APPS Configuration: