0
0
Djangoframework~20 mins

Database configuration in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Django Database Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the default database engine in Django's settings?
In a new Django project, what database engine is used by default in the DATABASES setting?
Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
ASQLite
BMySQL
CPostgreSQL
DOracle
Attempts:
2 left
💡 Hint
Think about the simplest database that requires no extra setup.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Django database configuration
Which option contains a syntax error in the DATABASES setting for PostgreSQL?
Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydb',
        'USER': 'user',
        'PASSWORD': 'pass',
        'HOST': 'localhost',
        'PORT': '5432'
    }
}
ADATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydb', 'USER': 'user', 'PASSWORD': 'pass', 'HOST': 'localhost', 'PORT': '5432'}}
BDATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydb', 'USER': 'user', 'PASSWORD': 'pass', 'HOST': 'localhost' 'PORT': '5432'}}
C}}'2345' :'TROP' ,'tsohlacol' :'TSOH' ,'ssap' :'DROWSSAP' ,'resu' :'RESU' ,'bdym' :'EMAN' ,'lqsergtsop.sdnekcab.bd.ognajd' :'ENIGNE'{ :'tluafed'{ = SESABATAD
DDATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydb', 'USER': 'user', 'PASSWORD': 'pass', 'HOST': 'localhost', 'PORT': 5432}}
Attempts:
2 left
💡 Hint
Look for missing punctuation between keys.
state_output
advanced
1:30remaining
What will be the database NAME after this settings update?
Given this initial DATABASES setting, what is the value of DATABASES['default']['NAME'] after the update code runs?
Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
    }
}

# Update to PostgreSQL
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql'
DATABASES['default']['NAME'] = 'prod_db'
DATABASES['default']['USER'] = 'admin'
A'prod_db'
Bnull
C'db.sqlite3'
D'' (empty string)
Attempts:
2 left
💡 Hint
The update changes the NAME key after initial assignment.
🔧 Debug
advanced
2:00remaining
Why does this Django project fail to connect to the database?
This Django DATABASES setting causes a connection failure. What is the most likely cause?
Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '',
        'PORT': '',
    }
}
AMissing 'OPTIONS' key with SSL settings causes failure.
BEmpty 'HOST' and 'PORT' cause Django to fail connecting to MySQL server.
CUsing 'django.db.backends.mysql' requires installing a MySQL driver which might be missing.
DThe 'NAME' key must be a full file path for MySQL connections.
Attempts:
2 left
💡 Hint
Check if the database driver is installed and compatible.
🧠 Conceptual
expert
2:30remaining
How does Django handle multiple databases in settings?
If you configure multiple databases in Django's DATABASES setting, how does Django decide which database to use for a model by default?
ADjango uses the first database listed in the <code>DATABASES</code> dictionary for all models.
BDjango randomly picks one of the configured databases for each query.
CDjango requires specifying the database in each model's Meta class to select it.
DDjango uses the database named 'default' for all models unless routing is customized.
Attempts:
2 left
💡 Hint
Think about the meaning of the 'default' key in the DATABASES setting.