Home >>Django Tutorial >Django Database Connectivity

Django Database Connectivity

Django Database Connectivity

IN Django, the settings.py file contains all the project settings along with the database connection details. By default, Django works with the SQLite database but it also allows configuring for other databases as well.

Database connectivity will require all the connection details such as database name, user credentials, hostname, etc.

To connect with MySQL, django.db.backends.mysql driver is used to establishing a connection between the application and the database.

We will need to provide all the connection details in the setting file. The settings.py file will contain the following code for the database.

    'default': {  
        'ENGINE': 'django.db.backends.mysql',  
        'NAME': 'djangoApp',  

After providing all the details, we will check the connection using the migrate command.

$ python3 manage.py migrate  

This command will create tables for the admin, auth, contenttypes, and sessions.

Now, we can access to the MySQL database and see the database from the list of the databases. The created database will contain the following tables.