Django Configure Database Setting | Django Tutorials

Django Configure database setting copy

Django Configure Database Setting | Django Tutorials

Django Configure Database Setting

As you know we are publishing the Django tutorials series step by step, in today’s tutorial, you will learn all about “Django Configure Database Setting”, in which, we have discussed from basics of Databases to configure another database like MySQL, Postgres in Django project. Sure, you have understood different topics of Django but today’s lesson is very important to understand. Because without a Database you cannot build a good website or application. So lets to learn!

What is Database?

The database is the collection of logical data stored in such a way that easy to retrieve, filter, search, update or delete. Such kind of technology is linked with a website or web application or with any software to store required data. And provide data on the request of the user or admin.

Now a day, no website is without a database, every website or web application is using the database to keep the necessary data. There are software is used to store and manage the data is called DBMS. DBMS is the collection or set of different software or tools which work with data, as to store, retrieve, update, delete, control, manage, etc.
The person who does all the work inside DBMS like providing privileges to a user, creating and managing database, backup, and security, etc is called Database Administrator (DBA).
A shopping website has different types of products as product name, product price, product category, product discount, description, etc. How does this come from? A developer did not write all this information about data using hardcoded, but it comes from the database dynamically. How reach it in the database? There is a private area or admin area from that side a developer or website maintainer inserts different products that store in the database. And you see on the website homepage different products.

Why need of Database?

The following reason, due to that we use databases for a website or web-based application to store records.

  • The data store in the database is managed form
  • A database can contain millions of entries of data, which makes it easy to search specific data.
  • We can view all the data inside the database to display on application or website
  • The millions of data can be easily controlled if our data is stored in a database
  • The most important reason is that it makes easy accessibility for a website to retrieve data when required

Default Database in Django

If you are a beginner then you did not need to learn a Database at first then come to Django, but you can use and learn Django without going to database tutorials. But basic knowledge and information should be kept in your mind as we discussed here. So the default database in Django is the SQLite (Relational Database Management System ). SQLite is a lightweight database that is suitable for small data-contained websites.
When you installed Django, you did not need to install it, you will see it in your Django by default files. You are not bound to use only SQLite but you can use another database also, like PostgreSQL, MariaDB, MYSQL, etc. We have mentioned at the end how you can configure these databases in your Django project.
Recommended to learn:

Configuration of Database in Django

Django Configure Database Setting is very easy, but you need to know five things while configuring the database in your Django project. Those five things are mentioned below:

ENGINE: It is Django specific, it is the main and important line of code to add. This line, you get from the library which you install for a specific database, e.g MySQL or Postgres.
NAME: It is the name of the database, when you create a database, it asks you to enter your name of the database. That name you have to mention here e.g organization name, website name, etc
USER: There are different users of the database and may have different rights. You need to enter your database name for a specific database.
PASSWORD: When you give a user name, you should add to password also
PORT: It is the same number that helps to connect to that specific database properly.

Now, if you want to add a MySQL database, you need to read its requirements, for example to using MySQL you have to install a library that helps to connect with the MySQL database. Then you have to collect the above information. Then that information you will need to include in MySQL database configuration settings. (At the end of the article, I have mentioned)

Recommended to Lear:

Django Security Complete Guidelines

How to Django Configure database setting

Django support is other than sqlit3 database also like MySQL, Postgres, etc. You need to install the required Python-based libraries for that and use another database. Because sqlite3 is the light database management system which has some limitations. But you can use it with a lightweight website or application. So following, We have mentioned the Django configuration of two databases. You need to give details according to your information. I have mentioned general details.

# Django Configure database setting

'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mention_database_name',
'USER': 'mention_your_usernmae_here',
'PASSWORD': 'mention_your_password_for_that_used_for_Login',
'HOST': 'name of your host, incase of locally base, write localserver',
'PORT': 'mention port numebr',

'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'yourDBname',
'USER': 'yourOWNname_which you used for login',
'PASSWORD': 'mentionPassword_which you used for login',
'HOST': 'name of server, incase of locally, we used localserver',
'PORT': 'mention here port number',

Now! what you have to do?

As you have understood this article about “Django Configure Database Setting”, now you must follow instructions as discussed in this article. In case of any issues or problems, don’t worry, you can discuss them with us.

On other hand, If you have any suggestions or knowledge about this article, you can share it with us, we will appreciate you!

If this article is good then share it on FacebookTwitterPinterestInstagram, etc.

Advanced Tutorials for Beginners

Build a Django CRUD Application | Django Tutorials

What is Django Query Set API | Django Tutorial for Beginners

What are views in Django | Django Tutorials

30+ Python Web Application Projects Ideas | 100% Full Guide


Leave your thought here

Your email address will not be published. Required fields are marked *

Recent Comments

  1. Push it to the limit cool Wolf! You are the best and you can do everything! It'll all work out very very very soon! smkmkplobydlmcrjmzgvx 2396134 on Django Create superuser | Django Tutorial
  2. Thank you For your hard work over the years! For this, we give you the opportunity. For more information, see the instructions. skfhjvkjsdjsrbhvbsrfhkis 9357930 on Django Create superuser | Django Tutorial
  3. Thank you For your hard work over the years! For this, we give you the opportunity. For more information, see the instructions. skfhjvkjsdjsrbhvbsrfhkis 5948210 on Django Create superuser | Django Tutorial
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar

Get your Enrollment


Leave your details below and receive a discount coupon in your inbox