0
0
Djangoframework~10 mins

Database configuration in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the default database engine in Django settings.

Django
DATABASES = {
    'default': {
        'ENGINE': '[1]',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
Drag options to blanks, or click blank then click option'
A'django.db.backends.mysql'
B'django.db.backends.oracle'
C'django.db.backends.postgresql'
D'django.db.backends.sqlite3'
Attempts:
3 left
💡 Hint
Common Mistakes
Using MySQL or PostgreSQL engine strings by default.
Forgetting to include quotes around the engine string.
2fill in blank
medium

Complete the code to specify the database NAME for a PostgreSQL database in Django settings.

Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '[1]',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
Drag options to blanks, or click blank then click option'
Adb.sqlite3
Bmydatabase
Cpostgres
Ddefaultdb
Attempts:
3 left
💡 Hint
Common Mistakes
Using the SQLite file name instead of the PostgreSQL database name.
Leaving the NAME field empty.
3fill in blank
hard

Fix the error in the database configuration by completing the missing key for the database user.

Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        '[1]': 'admin',
        'PASSWORD': 'secret',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}
Drag options to blanks, or click blank then click option'
A'USERNAME'
B'USER_NAME'
C'USER'
D'LOGIN'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'USERNAME' or 'USER_NAME' instead of 'USER'.
Using 'LOGIN' which is not recognized by Django.
4fill in blank
hard

Fill both blanks to configure a PostgreSQL database with the correct engine and port.

Django
DATABASES = {
    'default': {
        'ENGINE': '[1]',
        'NAME': 'mydb',
        'USER': 'user',
        'PASSWORD': 'pass',
        'HOST': 'localhost',
        'PORT': '[2]',
    }
}
Drag options to blanks, or click blank then click option'
Adjango.db.backends.postgresql
B5432
C3306
Ddjango.db.backends.mysql
Attempts:
3 left
💡 Hint
Common Mistakes
Using MySQL port 3306 with PostgreSQL engine.
Mixing engine and port values.
5fill in blank
hard

Fill all three blanks to configure a MySQL database with correct engine, host, and port.

Django
DATABASES = {
    'default': {
        'ENGINE': '[1]',
        'NAME': 'mydb',
        'USER': 'user',
        'PASSWORD': 'pass',
        'HOST': '[2]',
        'PORT': '[3]',
    }
}
Drag options to blanks, or click blank then click option'
Adjango.db.backends.mysql
Blocalhost
C3306
D127.0.0.1
Attempts:
3 left
💡 Hint
Common Mistakes
Using PostgreSQL engine with MySQL port.
Using 'localhost' instead of '127.0.0.1' for host in some cases.